How to make a QSqlRelationalTableModel that is a view into another QSqlRelationalTableModel?
-
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.@jonb wow thanks, that's exactly the part i didn't quite understand yet! perfect!
-
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?
@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.@jonb wow thanks, that's exactly the part i didn't quite understand yet! perfect!