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. TreeView with functionality to go back and forth flat list and hierarchical view?
QtWS25 Last Chance

TreeView with functionality to go back and forth flat list and hierarchical view?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.0k Views
  • 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.
  • Thuan_FirelightT Offline
    Thuan_FirelightT Offline
    Thuan_Firelight
    wrote on last edited by
    #1

    Hi all,

    I am looking for the best approach or recommended approach to implementing a tree view which can display as a flat list as well as hierarchical view via a toggle button.

    The target widget taking the model is a QTreeView. I already have a tree model class that implements QAbstractItemModel and the hierarchical aspect is all sorted. What I need now is a way for the same tree view to display the items as a flat list. I can either create a brand new model and pass that to the tree view or write a class implementing a QAbstractProxyModel and pass that to the tree view instead. I am attempting option 2. I was looking at deriving QIdentityProxyModel with a flag in my derived class that determines if I should do some other logic if displaying as a flat list or forward calls (e.g. mapFromSource, mapToSource, etc) to the QIdentityProxyModel if displaying as a hierarchy.

    Does this sound like a sensible approach? I had a go at this and it seems Qt is still passing me old proxy indices created by QIdentityProxyModel even when the view is in the flat list model. Is there something I need to do to force the UI to refresh so it would call index() to generate the new proxy index for each item?

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

      Hi,

      What about having two views on your model rather that trying to fit everything in a tree view ?

      You can then use a QStackedLayout and switch between the views.

      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
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        I think you are describing exactly the functionality of KDescendantsProxyModel

        "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

        • Login

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