[Development] filtering using QSortFilterProxyModel

Olivier Goffart olivier at woboq.com
Sat Sep 28 11:05:17 CEST 2013


On Saturday 28 September 2013 18:41:38 h wrote:
> Hi all,
> Firstly, I am off line a fair bit at the moment, so if you can reply to
> this post it will be greatly appreciated, but I may be slow to respond.
> 
> I am wanting to filter data from a QAbstractTableModel into a
> QTableView through a QSortFilterProxyModel.  I have the app working
> well, with sort implemented in my QSortFilterProxyModel subclass.
> 
> I have QDate data in my table and am wanting to display data only from
> selected days, ranges of days or days of the week.
> 
> >From my reading of the documentation, QSortFilterProxyModel will filter
> 
> on a regex, but nothing else.  Is this correct?  I would like to write
> a function returning a boolean that will either drop the dataitem or
> pass it through.  I cannot see how to do this.
> 
> Can someone please advice on how to filter based on data types, not
> just strings, which I believe is a condition of regex?
> I would like to introduce a number of more complex filters than just
> date, so a solution to something beyond regex rather than how to
> express date as a regex would be appreciated.

Hi,

This mailing list is there for discussions about contributions to Qt.
For questions about Qt, there is the qt-interest mailinglist which you can use 
in the future.

Regarding your question, you can simply reimplement 
QSortFilterProxyModel::filterAcceptsRow.  And don't forget to call 
invalidateFilter when the filter changes.


-- 
Olivier

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org




More information about the Development mailing list