how to use QSortFilterProxyModel with QtreeWidget?
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:
Code:
sourceModel = ui.treeWidget->model();
proxyModel->setSourceModel(sourceModel);
ui.treeWidget->setModel(proxyModel);
proxyModel
->setFilterRegExp
(QRegExp(".png", Qt
::CaseInsensitive,
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:
Code:
/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
any idea how to do it right?
I have another question, the doc says about QSortFilterProxyModel
Quote:
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
Re: how to use QSortFilterProxyModel with QtreeWidget?
I believe that in order to be able to call setModel you will need to use a QTableView rather than a QTableWidget.
Re: how to use QSortFilterProxyModel with QtreeWidget?
that´s ok thanx I found out. I had to use:
Code:
ui.treeWidget->QtreeWidget::setModel(proxyModel);
instead of
Code:
ui.treeWidget->setModel(proxyModel);
Re: how to use QSortFilterProxyModel with QtreeWidget?
QTreeWidget has it's own strictly private model and it is not meant to be changed by hacking like you do (assuming that is QTreeView::setModel() you are calling). I doubt it would work very well.. QTreeWidget implementation for example does some casting which assumes that model indexes' internal pointers point to a QTreeWidgetItem. This is not true in your case when you have changed the underlying model. The methods like QTreeWidget::model() and QTreeWidget::setModel() have not been declared as private with no reason.
Use a QTreeView if you want to use a model rather than the item approach QTreeWidget offers!
Re: how to use QSortFilterProxyModel with QtreeWidget?
Quote:
Originally Posted by
jpn
QTreeWidget has it's own strictly private model and it is not meant to be changed by hacking like you do (assuming that is QTreeView::setModel() you are calling). I doubt it would work very well.. QTreeWidget implementation for example does some casting which assumes that model indexes' internal pointers point to a QTreeWidgetItem. This is not true in your case when you have changed the underlying model. The methods like QTreeWidget::model() and QTreeWidget::setModel() have not been declared as private with no reason.
Use a QTreeView if you want to use a model rather than the item approach QTreeWidget offers!
And if i want to change the display text of the my files in QTreeView? Do you know how can i do? This is my big problem, right now...
With QTreeView i can to change the model to QFileSystemModel and in QTreeWidget i can't. But in QTreeWidget i can to change the text files display and in QTreeView i can't. And i need both, to change text files display and to use QFileSystemModel. =/
If can you help me...