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?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 331 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 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
    • JonBJ JonB

      @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 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 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?

        JonBJ 1 Reply Last reply
        0
        • D davecotter

          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?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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
          2
          • JonBJ JonB

            @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 last edited by
            #4

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

            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