How to get the index of the sourceModel of QSortFilterProxyModel
-
How can I get the index of the sourceModel of a QSortFilterProxyModel()? I have a QSortFilterProxyModel as the model in a tableView. The selectionChanged singal of the tableView is connected to on_selectionChanged. In on_selectionChanged selected contains the index of the QSortFilterProxyModel. How can I get the index of the sourceModel which corresponds to the index of the QSortFilterProxyModel?
I have something like this:
// Get the filter model m_accountFilterModel = m_accountModel->accountFilterModel(); // m_accountFilterModel is a QSortFilterProxyModel m_ui->tableViewApprovals->setModel(m_accountFilterModel()); connect(m_ui->tableViewApprovals->selectionModel(), &QItemSelectionModel::selectionChanged, this, &WidgetApprovalAccount::on_selectionChanged); . . . void WidgetApprovalAccount::on_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { Q_UNUSED(deselected) // How can I get the QItemSelection of m_accountModel here? }
-
@Infinity
QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const
, https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapToSourceReturns the source model index corresponding to the given proxyIndex from the sorting filter model.
Also see
QItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const
, https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapSelectionFromSourceReturns a source selection mapped from the specified proxySelection.