I use QtreeWidget to load an xml xbel file using the sax example given with Qt4.
I would like to put a lineEdit and use it to filter my QtreeWidget like konqueror bookmark editor does (or amarok etc...).
Here is the code I use, following the documentation exemple:
sourceModel = ui.treeWidget->model();
proxyModel->setSourceModel(sourceModel);
ui.treeWidget->setModel(proxyModel);
proxyModel
->setFilterRegExp
(QRegExp(".png", Qt
::CaseInsensitive,
QAbstractItemModel * sourceModel;
sourceModel = ui.treeWidget->model();
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(sourceModel);
ui.treeWidget->setModel(proxyModel);
proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive,
QRegExp::FixedString));
To copy to clipboard, switch view to plain text mode
The problem is that setModel doesn´t work that way with QtreeWidget, it seems to be private or something, here is the error I get on compile:
/usr/local/Trolltech/Qt-4.2.0-tp1/include/QtGui/qtreewidget.h:301: error: "virtual void QTreeWidget::setModel(QAbstractItemModel*)" is private
myapp.cpp:108: error: within this context
make: *** [myapp.o] Error 1
/usr/local/Trolltech/Qt-4.2.0-tp1/include/QtGui/qtreewidget.h:301: error: "virtual void QTreeWidget::setModel(QAbstractItemModel*)" is private
myapp.cpp:108: error: within this context
make: *** [myapp.o] Error 1
To copy to clipboard, switch view to plain text mode
any idea how to do it right?
I have another question, the doc says about QSortFilterProxyModel
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. How could I do that?
Thanx in advance
Pat
Bookmarks