Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ComboBox filtering treeWidget ?
Forum Updated to NodeBB v4.3 + New Features

ComboBox filtering treeWidget ?

Scheduled Pinned Locked Moved General and Desktop
pythonqtdesignerqsortfilter
6 Posts 3 Posters 2.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Heya
    wrote on last edited by Heya
    #1

    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)

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Heya
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4
          • 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)

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1
          • H Offline
            H Offline
            Heya
            wrote on last edited by Heya
            #5

            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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              IIRC something like:

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved