Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML TreeView - expansion status of hidden nodes
Forum Updated to NodeBB v4.3 + New Features

QML TreeView - expansion status of hidden nodes

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 120 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.
  • B Offline
    B Offline
    Bob64
    wrote last edited by
    #1

    In porting to Qt 6 TreeView I am finding it tricky to reimplement some behaviour that I had in Qt 5. It seems that the API for programmatically setting nodes collapsed or expanded is now based on the visible rows. In Qt 5 it was based on model index.

    One might wonder why I am interested in expanding nodes that can't be seen. The reason is that various behaviours are specified such that certain nodes should be default expanded or contracted when first added to the tree. Some of these "expanded" nodes are children of nodes that initially default to contracted - in other words, they are expanded but this won't be seen until their parent is expanded.

    Note that the tree view itself cares about the expansion status of nodes that can't currently be seen. If a node is expanded and its parent is then collapsed and re-expanded, the child will remain expanded.

    With the old approach I could deal with the expansion status of an entire newly added branch as soon as it was added and then I could forget about it. The normal tree behaviour would take over. With the new API I am going to have to listen for the expanded and collapsed signals to apply the default expansions, but only for the first time that relevant nodes become visible.

    I guess it's a long shot, but I wondered if anyone had already dealt with anything like this. It feels like it could be solved by adding an "isExpanded" flag to the model nodes, but I don't want to pollute the model with concerns of presentation state. Perhaps I could do it by having some sort of proxy model wrapper that I instantiate in the TreeView, which layers in the flag for the expansion state and delegates the rest to the actual model.

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote last edited by
      #2

      Have you tried calling expand with the result of cellAtIndex?

      B 2 Replies Last reply
      0
      • GrecKoG GrecKo

        Have you tried calling expand with the result of cellAtIndex?

        B Offline
        B Offline
        Bob64
        wrote last edited by
        #3

        @GrecKo Thanks for the suggestion. I haven't tried it yet, but I suspect that cellAtIndex will only provide row and column position consistent with the current visible rows in the tree, which would be no better than what I have now. I will give it a go though and report back.

        1 Reply Last reply
        0
        • GrecKoG GrecKo

          Have you tried calling expand with the result of cellAtIndex?

          B Offline
          B Offline
          Bob64
          wrote last edited by Bob64
          #4

          @GrecKo As expected, I get (-1, -1) cell coordinates back for non-visible indices.

          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