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 expand() method not working
Forum Updated to NodeBB v4.3 + New Features

QML TreeView expand() method not working

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 4.0k Views 1 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.
  • B Offline
    B Offline
    buckTarle
    wrote on 23 Jan 2017, 13:15 last edited by
    #1

    Hi there !

    I am currently using a QML TreeView based on a c++ model that is built when the user select some data to be showed.
    It is working correctly and I can expand or collapse it myself by clicking on the button.

    I would like it to be fully expanded every time it is charged but I can't get the expand() method to work.
    I tried with this line but without success :

    myTreeView.expand(treeView.rooIndex);
    

    QUESTION : Do I need to implement something in my cpp model for it to work ? Or maybe I just missed something else ?

    ps : It might be related to the TreeModel::index() method of the model which I was not sure how to implement.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nx7z
      wrote on 17 Feb 2017, 09:06 last edited by
      #2

      Hi Buck,

      I was facing the same issue. I "solved" it by using this loop:

      function expandAll() {
          for(var i=0; i < myModel.rowCount(); i++) {
              var index = myModel.index(i,0)
              if(!myTreeView.isExpanded(index)) {
                  myTreeView.expand(index)
              }
          }
      }
      

      But it's delicate, because you can't call it while filling the model. Only after it is done. Otherwise the TreeView won't work/look properly. For me TreeView is only a have done Control. I'm missing an attribute in TreeView "alwaysExpanded" or something.

      Hope this helps!
      Best,
      Nexu

      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