[Interest] Can QSortFilterProxyModel sort the filtered data only?

Mark Gaiser markg85 at gmail.com
Tue Apr 8 17:41:50 CEST 2014


Hi,

When reading through the QSortFilterProxyModel i get the feeling that
sorting is done on the source model regardless of a filter.

That is no problem with small models since sorting is quite fast, but
that can be a bit of a pain if you have millions of entries (which
filters reduce to hundreds) then sorting still seems to sort all
entries (as if nothing is filtered) which takes a bit of time.

A detour that would probably work is wrapping a QSortFilterProxyModel
(with just the filter) in another QSortFilterProxyModel and sorting on
that (since it's source would be a filtered model). This approach
basically makes one a "QFilterProxyModel" and the other a
"QSortProxyModel" which smells wrong.

Another way would be to re-implement QAbstractProxyModel and
implementing my own sorting and filtering, but i'd like to prevent
that if possible.

What i'm hoping for is some option in QSortFilterProxyModel where you
can define how you want to sort:
- Sort source model (sorts all data)
- Sort proxy model (sorts data that passed the filtered)

But such an option doesn't seem to exist.

Cheers,
Mark



More information about the Interest mailing list