PDA

View Full Version : Checking if a row in a tableview is filtered when using a QSortFilterProxyModel



snydesc
27th September 2012, 17:19
I have a tableview that uses a QSortFilterProxyModel. If I call tableView.isRowHidden() on a row that was filtered it will return false. I would have expected it to return true since the row is hidden. I could not find a isRowFiltered() function anywhere. How can I tell if a row is filtered within my table?

norobro
27th September 2012, 23:07
You're confusing a function of the view (hiding rows) with a function of the model (filtering).

A filtered out row isn't hidden in the view, it will not exist in your proxy model.

From the QSortFilterProxyModel (http://qt-project.org/doc/qt-4.8/qsortfilterproxymodel.html#details) docs:
The model transforms the structure of a source model by mapping the model indexes it supplies to new indexes, corresponding to different locations, for views to use.

You can check whether a row is filtered or not by using QSortFilterProxyModel::mapFromSource().

if(!mapFromSource(sourceModel()->index("source model row",0)).isValid()) //source model row is filtered;