Important: Please read the Qt Code of Conduct -

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
    connect(m_ui->tableViewApprovals->selectionModel(), &QItemSelectionModel::selectionChanged,  this, &WidgetApprovalAccount::on_selectionChanged);
    void WidgetApprovalAccount::on_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
        // How can I get the QItemSelection of m_accountModel here?

  • @Infinity
    QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const,

    Returns the source model index corresponding to the given proxyIndex from the sorting filter model.

    Also seeQItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const,

    Returns a source selection mapped from the specified proxySelection.

  • @JonB Awesome! Thanks. That is what I was looking for.

Log in to reply