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. Change filtered data representation in a tree using QStandardItemModel
Forum Updated to NodeBB v4.3 + New Features

Change filtered data representation in a tree using QStandardItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 527 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.
  • giupignaG Offline
    giupignaG Offline
    giupigna
    wrote on last edited by
    #1

    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.

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

      Hi,

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

      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