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)



  • This post is deleted!

  • Lifetime Qt Champion

    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 to setFilterFixedString 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


  • Lifetime Qt Champion

    IIRC something like:

    ui.filters.currentTextChanged.connect(proxyModel.setFilterFixedString)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.