Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get the index of the sourceModel of QSortFilterProxyModel

How to get the index of the sourceModel of QSortFilterProxyModel

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Infinity
    wrote on last edited by
    #1

    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?
    }
    
    JonBJ 1 Reply Last reply
    0
    • I Infinity

      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?
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Infinity
      QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const , https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapToSource

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

      Also seeQItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const, https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapSelectionFromSource

      Returns a source selection mapped from the specified proxySelection.

      I 1 Reply Last reply
      1
      • JonBJ JonB

        @Infinity
        QModelIndex QSortFilterProxyModel::mapToSource(const QModelIndex &proxyIndex) const , https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapToSource

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

        Also seeQItemSelection QSortFilterProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const, https://doc.qt.io/qt-5/qsortfilterproxymodel.html#mapSelectionFromSource

        Returns a source selection mapped from the specified proxySelection.

        I Offline
        I Offline
        Infinity
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved