QTableView, set arbitrary selection of rows.
-
I'm using a QTableView with a custom model. I want to change the arbitrary selection of rows after a manipulation of the model data.
So first row 1,5,8 are selected, then the data of these rows are moved upwards in the vector, and the selection should also move upwards, to 0,4 and 7. But there seems no method for setting a selection in a QTableView. Am I missing something?
-
Well. I got it. It think. Almost all roads are a dead end for requiring a QModelIndex (which you cannot create from a Row/Col), or bump into a protected method.
The most obvious solution is using, QTableView::setSelection. But it's protected.
So you cannot access that from your model, or from the QMainWindow.But there seems to be this way:
ui->tableView->selectionModel()->select(ui->tableView->model()->index(row,0) ,QItemSelectionModel::Toggle|QItemSelectionModel::Rows);