PyQt: Getting the index of an appended row after QStandardItemModel.appendRow()

114 views Asked by At

I am appending a row in PyQt like so:

model = QStandardItemModel(0, 3)
model.appendRow([item1, item2, item2])

Now I would like to get the QModelIndex of the appended row so that I can select the row in the user interface using QItemSelectionModel.select(). How can this be done?

1

There are 1 answers

0
knipknap On

Not quite the universal answer, but in my specific case this was enough:

model = QStandardItemModel(0, 3)
model.appendRow([item1, item2, item2])
last_row = model.rowCount() - 1
self.myTableView.selectRow(last_row)