Problem getting selected item from QTreeView + QSortFilterProxyModel
Hi,
I'm not being able to read the selected item from a QTreeView when it's being sorted by a QSortFilterProxyModel. All the references from currentIndex(), currentIndex().row(), selectionModel()->currentIndex() or whatever are always returning the row number in QTreeview, but I cannot find the correct record in the original model using the row number as the sorting process seems to be not affecting the sequence of data in the model. I'm using the QSqlQueryModel.
Am I doing something wrong here? I would appreciate any suggestion....
Thank-you,
Renato A. Ferreira
Re: Problem getting selected item from QTreeView + QSortFilterProxyModel
The indexes returned by the view's selection model are obviously from the model that the view works on.
In your case the proxy model.
They don't make any sense in the context of the proxy's source model.
If you really need an index of the source model, use the proxy's mapToSource() function.
If you just need data from the index, use its data() function.
Cheers,
_
Re: Problem getting selected item from QTreeView + QSortFilterProxyModel
Perfect! It worked with mapToSource()...
Code:
mainModel.record(proxyModel->mapToSource(ui->treeView->currentIndex()).row())
And now I can access the primary key to search the rest of data from database.
Thank-you!