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 make a QSqlRelationalTableModel that is a view into another QSqlRelationalTableModel?

How to make a QSqlRelationalTableModel that is a view into another QSqlRelationalTableModel?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 336 Views
  • 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.
  • D Offline
    D Offline
    davecotter
    wrote on 19 Aug 2019, 23:17 last edited by
    #1

    okay so i have QSqlRelationalTableModel, with all possible rows and columns.

    but in my VIEW i want only SOME of the rows and SOME of the columns visible. If i just do this:

    ui->tracksList->setModel(&sqlP->i_sql_model);

    then i get ALL rows and columns. what's the proper method for having a model-backed table view that only shows some of what's in the model?

    i have a "playlist" table that contains just the rows i want, and i have a vector of IDs that contains just the columns (and in what order) i want. how do i cause the "tracksList" view to show only that info?

    1 Reply Last reply
    0
    • J JonB
      20 Aug 2019, 18:27

      @davecotter
      The Qt way of doing this is not in the view. Rather, interpose a QSortFilterProxyModel (override filterAcceptsRow/Column()) and/or a QIdentityProxyModel between the view and your actual model. So you set QAbstractItemView::setModel() to the interposed QAbstractProxyModel and QAbstractProxyModel::setSourceModel() to your underlying model. https://doc.qt.io/qt-5/model-view-programming.html#proxy-models gives the overview and rationale.

      D Offline
      D Offline
      davecotter
      wrote on 20 Aug 2019, 20:24 last edited by
      #4

      @jonb wow thanks, that's exactly the part i didn't quite understand yet! perfect!

      1 Reply Last reply
      0
      • D Offline
        D Offline
        davecotter
        wrote on 20 Aug 2019, 16:08 last edited by
        #2

        it seems that the option is to go ahead and set the model into the view, then use the viewer apis to HIDE all the rows and columns i do not want to see? is this really the best approach?

        J 1 Reply Last reply 20 Aug 2019, 18:27
        0
        • D davecotter
          20 Aug 2019, 16:08

          it seems that the option is to go ahead and set the model into the view, then use the viewer apis to HIDE all the rows and columns i do not want to see? is this really the best approach?

          J Offline
          J Offline
          JonB
          wrote on 20 Aug 2019, 18:27 last edited by JonB
          #3

          @davecotter
          The Qt way of doing this is not in the view. Rather, interpose a QSortFilterProxyModel (override filterAcceptsRow/Column()) and/or a QIdentityProxyModel between the view and your actual model. So you set QAbstractItemView::setModel() to the interposed QAbstractProxyModel and QAbstractProxyModel::setSourceModel() to your underlying model. https://doc.qt.io/qt-5/model-view-programming.html#proxy-models gives the overview and rationale.

          D 1 Reply Last reply 20 Aug 2019, 20:24
          2
          • J JonB
            20 Aug 2019, 18:27

            @davecotter
            The Qt way of doing this is not in the view. Rather, interpose a QSortFilterProxyModel (override filterAcceptsRow/Column()) and/or a QIdentityProxyModel between the view and your actual model. So you set QAbstractItemView::setModel() to the interposed QAbstractProxyModel and QAbstractProxyModel::setSourceModel() to your underlying model. https://doc.qt.io/qt-5/model-view-programming.html#proxy-models gives the overview and rationale.

            D Offline
            D Offline
            davecotter
            wrote on 20 Aug 2019, 20:24 last edited by
            #4

            @jonb wow thanks, that's exactly the part i didn't quite understand yet! perfect!

            1 Reply Last reply
            0

            1/4

            19 Aug 2019, 23:17

            • Login

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