QTableView, QSortFilterProxyModel row selection
-
I have a QTableView this contains records from a database. I've implemented column sorting using QSortFilterProxyModel.
Before QSortFilterProxyModel, to get a row selection I used:
QItemSelectionModel* pobjModel(mptvSDrecs->selectionModel()); QModelIndexList objIndexes(pobjModel->selectedIndexes());
This worked, however now this doesn't return the correct row. Should I have changed something else?
This is how I added the filter model:
mptvSDrecs = new QTableview(this); mpsiSDmodel = new QStandardItemModel(this); mpsfpSDmodel = new QSortFilterProxyModel(this); mptvSDrecs->setSelectionBehavior(QAbstractItemView::SelectRows); mptvSDrecs->setStyleSheet(DataSets::mscszTableViewStyle); mpsfpSDmodel->setSourceModel(mpsiSDmodel); mptvSDrecs->setModel(mpsfpSDmodel); mptvSDrecs->setSortingEnabled(true);
-
@SGaist said in QTableView, QSortFilterProxyModel row selection:
QItemSelectionModel::selection
Thank you, is there an example which demonstrates how to use these?
Found https://stackoverflow.com/questions/18128722/convert-qsqlquerymodel-data-into-qvectors/18130955#18130955, do I need to sub-class QAbstractProxyModel ?
@SPlatten said in QTableView, QSortFilterProxyModel row selection:
is there an example which demonstrates how to use these?
const QItemSelection proxySelect = mptvSDrecs->selectionModel()->selection(); QModelIndexList objIndexes = mpsfpSDmodel->mapSelectionToSource(proxySelect)->indexes();
-
Hi,
What you have selected there are the indexes from the proxy model.
From the top of my head you need to map that selection to the source model. Check QSortFilterProxyModel::mapSelectionToSource and QItemSelectionModel::selection.
-
Hi,
What you have selected there are the indexes from the proxy model.
From the top of my head you need to map that selection to the source model. Check QSortFilterProxyModel::mapSelectionToSource and QItemSelectionModel::selection.
@SGaist said in QTableView, QSortFilterProxyModel row selection:
QItemSelectionModel::selection
Thank you, is there an example which demonstrates how to use these?
Found https://stackoverflow.com/questions/18128722/convert-qsqlquerymodel-data-into-qvectors/18130955#18130955, do I need to sub-class QAbstractProxyModel ?
-
@SGaist said in QTableView, QSortFilterProxyModel row selection:
QItemSelectionModel::selection
Thank you, is there an example which demonstrates how to use these?
Found https://stackoverflow.com/questions/18128722/convert-qsqlquerymodel-data-into-qvectors/18130955#18130955, do I need to sub-class QAbstractProxyModel ?
@SPlatten said in QTableView, QSortFilterProxyModel row selection:
is there an example which demonstrates how to use these?
const QItemSelection proxySelect = mptvSDrecs->selectionModel()->selection(); QModelIndexList objIndexes = mpsfpSDmodel->mapSelectionToSource(proxySelect)->indexes();