qt5qtableviewqstandarditemmodelqsortfilterproxymodel

selection model getting wrong index when working with QSortFilterProxyModel


I have QStandardItemModel with own QSortFilterProxyModel to filter hidden entry in QTableView. when I select entry from this view below signal is emitted from selection model.

view_table->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)

Suppose I have 5 entry in list and entry no. 4 is hidden. when I select entry no. 5 above signal giving me current Index as entry no. 4 of hidden item.

how can I select correct Index (should be 5) when item is hidden in list?


Solution

  • I think what you're looking for is QSortFilterProxyModel::mapToSource. It takes the proxy's index and returns the corresponding index from the source model.

    QModelIndex proxyIndex = <whatever>
    QModelIndex sourceIndex = myProxyModel.mapToSource(proxyIndex);