How to make a QSqlRelationalTableModel that is a view into another QSqlRelationalTableModel?
-
wrote on 19 Aug 2019, 23:17 last edited by
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?
-
@davecotter
The Qt way of doing this is not in the view. Rather, interpose a QSortFilterProxyModel (overridefilterAcceptsRow/Column()
) and/or a QIdentityProxyModel between the view and your actual model. So you setQAbstractItemView::setModel()
to the interposedQAbstractProxyModel
andQAbstractProxyModel::setSourceModel()
to your underlying model. https://doc.qt.io/qt-5/model-view-programming.html#proxy-models gives the overview and rationale.wrote on 20 Aug 2019, 20:24 last edited by@jonb wow thanks, that's exactly the part i didn't quite understand yet! perfect!
-
wrote on 20 Aug 2019, 16:08 last edited by
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?
-
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?
wrote on 20 Aug 2019, 18:27 last edited by JonB@davecotter
The Qt way of doing this is not in the view. Rather, interpose a QSortFilterProxyModel (overridefilterAcceptsRow/Column()
) and/or a QIdentityProxyModel between the view and your actual model. So you setQAbstractItemView::setModel()
to the interposedQAbstractProxyModel
andQAbstractProxyModel::setSourceModel()
to your underlying model. https://doc.qt.io/qt-5/model-view-programming.html#proxy-models gives the overview and rationale. -
@davecotter
The Qt way of doing this is not in the view. Rather, interpose a QSortFilterProxyModel (overridefilterAcceptsRow/Column()
) and/or a QIdentityProxyModel between the view and your actual model. So you setQAbstractItemView::setModel()
to the interposedQAbstractProxyModel
andQAbstractProxyModel::setSourceModel()
to your underlying model. https://doc.qt.io/qt-5/model-view-programming.html#proxy-models gives the overview and rationale.wrote on 20 Aug 2019, 20:24 last edited by@jonb wow thanks, that's exactly the part i didn't quite understand yet! perfect!
1/4