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. QSortFilterProxyModel - How to add an extra column.

QSortFilterProxyModel - How to add an extra column.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.6k 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.
  • M Offline
    M Offline
    mawh
    wrote on last edited by
    #1

    Hello All,

    I'm trying to create a QSortFilterProxyModel subclass which has as its source a QSqlTableModel and provides two extra cols to supply extra data to view that is not in the source model.

    Where I'm having trouble is with the reimplemented index() method.

    From what I understand, if the column parameter is one of the 'extra' columns, I need to return an index using createIndex().
    What does one supply as the third parameter to createIndex() ?

    Thanks,
    Mike

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mawh
      wrote on last edited by
      #2

      I think I've figured it out.

      Since the source model in my case is a table ( as opposed to a tree ) model, reimplementing the parent() method to simply return an invalid index allows me to call createIndex() with simply the row and column.

      @
      QModelIndex CustomSortFilterProxyModel::parent(const QModelIndex &child) const
      {
      return QModelIndex();
      }

      QModelIndex CustomSortFilterProxyModel::index(int row, int column, const QModelIndex &parent) const
      {
      if ( row < rowCount() ) {
      switch ( column ) {
      case extraCol1:
      case extraCol2:
      return createIndex(row, column);
      }
      }
      return QSortFilterProxyModel::index(row, column, parent);
      }
      @

      Of course to fully support the additional columns, the following methods were also reimplemented:

      • columnCount()
      • data()
      • flags()
      • headerData()
      • mapToSource()
      • mapFromSource()

      Mike

      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