开发者

QTableView filtering with QSortFilterProxyModel (grouping filters)

It seems I am not capable of filtering more then one column at once. I think it's common usage when using filters, maybe I'm missing something.

For example, i have 4 columns in my QTableView, let's say column X (string), Y (int), Z (st开发者_运维百科ring), Q (string). I wish to filter by filter_1 column X and filter by filter_2 column Z. Is it possible to set QSortFilterProxyModel filter for more then one column (dynamically), but not all (re implementing filterAcceptsRow).

Thanks


You can use setFilterRegExp(), setFilterWildcard(), or setFilterFixedString() methods to set a filter. An example from QT doc is :

proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive,
                                             QRegExp::FixedString));
proxyModel->setFilterKeyColumn(1); 

If these methods are not sufficient, according to Qt documentation customizing proxy models is designed to be used via inheritance.

For advanced users, QSortFilterProxyModel can be subclassed, providing a mechanism that enables custom filters to be implemented.

In this case you need to sublass and override filterAcceptsRow() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜