PDA

View Full Version : How to make QSortFilterProxyModel search through children in a treeWidget?



patcito
7th July 2006, 21:49
Hey all,
I´m using a QSortFilterProxyModel to search through my QtreeWidget like this:


QAbstractItemModel * sourceModel;
sourceModel = ui.treeWidget->model();
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(sourceModel);
ui.treeWidget->QtreeWidget::setModel(proxyModel);
proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive,QRegExp::FixedString));


The problem is that as the documentation says:
"For hierarchical models, the filter is applied recursively to all
children. If a parent item doesn't match the filter, none of its
children will be shown."
I would like all parent items to be shown as long as one of their
children match the filter or of course if the parent itself matches
the filter. Kind of like how the collection tab in amarok works. Any
idea how could I do that?

thanx in advance

Pat

wysota
18th July 2006, 10:53
Reimplement either the sort proxy model or the abstract one and implement the functionality yourself. You'll probably want to cache the results as you have to be searching bottom-up and not top-down and it is more time consuming.