Change filtered data representation in a tree using QStandardItemModel



  • I have a tree structure using a QStandardItemModel. The model has only a rootItem and each item has one or more children. I added a search bar to find an item in the model.

    Suppose to have this tree structure:

    RootItem
    |_________ Item1
                  |_______Item 2
                  |_______Item 3
    |
    |_________ Item4
                  |_______Item 3
    |
    |_________ Item5
    

    If the user searches the string "Item 3" what I want to do is to display the results in the same treeView in the following way:

    RootItem
    |_________ Item1
                  |_______Item 3
    
    RootItem
    |_________ Item4
                  |_______Item 3
    

    How can I do it? Do I need to subclass the QSortFilterProxyModel or QIdentityProxyModel or something else? Of course I must not change the data structure in the source model.


  • Lifetime Qt Champion

    Hi,

    I'd subclass QSortFilterProxyModel and re-implement filterAcceptsRow. It's not what QIdentityProxyModel is designed for.


Log in to reply
 

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