PDA

View Full Version : Select row in QTableView after insert.



fede
14th April 2009, 01:58
Hello,

I would like to select a row in the a tableview after inserting it. I'm inserting the row as the last in the model, using QSqlTableModel.insertRow(QSqlTableModel.rowCount() ). I want to select the inserted row in a QTableView which uses this model.
My problem is I cannot find which row in the table view corresponds to the new row in the model. Or, in other words: given a row in the model, how can I know the row where it's displayed in the table?

Thanks !

fede
14th April 2009, 15:18
Sorry... should have looked around further: the answer is here (http://www.qtcentre.org/forum/f-newbie-4/t-how-to-select-a-cell-in-a-qtableview-11723.html)



QModelIndex i; // ?
table->selectionModel()->select(i, QItemSelectionModel::Select);


Since I also have a QSortFilterProxyModel between the model and the view, I had to use QSortFilterProxyModel.mapFromSource to convert the model index to the filter proxy's index (the table view has the filter proxy set as it's model).