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
Forum Updated to NodeBB v4.3 + New Features

How to get the index of the sourceModel of QSortFilterProxyModel

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k 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 7 Mar 2020, 18:50 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?
    }
    
    J 1 Reply Last reply 7 Mar 2020, 18:52
    0
    • I Infinity
      7 Mar 2020, 18:50

      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?
      }
      
      J Online
      J Online
      JonB
      wrote on 7 Mar 2020, 18:52 last edited by JonB 3 Jul 2020, 19:00
      #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 7 Mar 2020, 19:06
      1
      • J JonB
        7 Mar 2020, 18:52

        @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 7 Mar 2020, 19:06 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        7 Mar 2020, 18:50

        • Login

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