ComboBox filtering treeWidget ?
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
This post is deleted!
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
currentTextChangedfrom the combobox to
- 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 ?
tree1 = QTreeWidget()
sourceModel = MyItemModel()
proxyModel = QSortFilterProxyModel()
I used PySide doc as example
IIRC something like: