ComboBox filtering treeWidget ?
-
Hello,
I got a combobox called " filters " with 2 items in it(blue and red)
And a treewidget called tree1 with 2 columns ( name and color )
What i want is that if i choose "red" as filter in my combobox, only item with "red" as color would be showed on my treewidget.i've heard i should use QSortFilterProxyModel but i have no idea how to do
Thanks
(python)
-
Hi,
Please have some patience and allow 24 hours before bumping your own thread. This is a community forum with people not necessarily living in the same time zone as you.
As for your question, you're likely looking to use QSortFilterProxyModel:: filterRegExp with the content of your combo box.
-
- separate QTreeWidget in a QTreeView and a QStandardItemModel.
- create a QSortFilterProxyModel and set the QStandardItemModel as its suorce model
- connect
currentTextChanged
from the combobox tosetFilterFixedString
of QSortFilterProxyModel - if you need the filtering to be recursive then you can replace QSortFilterProxyModel with KRecursiveFilterProxyModel (I have no idea if/how you can use it in python though)
-
Sorry but could you just give me the code ?
I tried:
tree1 = QTreeWidget()
sourceModel = MyItemModel()proxyModel = QSortFilterProxyModel()
tree1.setModel(proxyModel)
proxyModel.setFilterRegExp(QRegExp(".PNG", Qt.CaseIntensive,QRegExp.FixedString))ui.filters.CurrentIndexChanged.connect(?)
I used PySide doc as example
-
IIRC something like:
ui.filters.currentTextChanged.connect(proxyModel.setFilterFixedString)