On 10/25/2022 1:03 PM, DFS wrote:
Having problems with removeRow() on a QTableView object.

removeRow() isn't listed as being a method of a QTableView, not even an inherited method, so how are you calling removeRow() on it? (See https://doc.qt.io/qt-6/qtableview-members.html)

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())


--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to