Any PyQt developers here?

DFS nospam at dfs.com
Tue Oct 25 13:03:58 EDT 2022


Having problems with removeRow() on a QTableView object.

After calling removeRow(), the screen isn't updating.  It's as if the 
model is read-only, but it's a QSqlTableModel() model, which is not 
read-only.

The underlying SQL is straightforward (one table) and all columns are 
editable.

None of the editStrategies are working either.

I tried everything I can think of, including changes to the 
EditTriggers, but no luck.  HELP!

FWIW, the same removeRow() code works fine with a QTableWidget.

-------------------------------------------------------------------
object creation and data loading all works fine
-------------------------------------------------------------------
#open db connection
qdb = QSqlDatabase.addDatabase("QSQLITE")
qdb.setDatabaseName(dbname)
qdb.open()

#prepare query and execute to return data
query = QSqlQuery()
query.prepare(cSQL)
query.exec_()

#set model type and query
model = QSqlTableModel()
model.setQuery(query)
		
#assign model to QTableView object
view = frm.tblPostsView
view.setModel(model)
		
#get all data
while(model.canFetchMore()): model.fetchMore()
datarows = model.rowCount()



-------------------------------------------------------------------
iterate selected rows also works fine
SelectionMode is Extended.
identical code works for a QTableWidget
-------------------------------------------------------------------
selected = tbl.selectionModel().selectedRows()
#reverse sort the selected items to delete from bottom up
selected = sorted(selected,reverse=True)
for i,val in enumerate(selected):
	tbl.model().removeRow(selected[i].row())



More information about the Python-list mailing list