Important: Please read the Qt Code of Conduct -

Change height of QML TreeView as it expands?

  • Is there a way to have the QML TreeView change its height parameter as it expands to show more content?

  • This looked promising, but it is not giving me good sizes:
    "This read-only property holds the collective position and size of the item's children.
    This property is useful if you need to access the collective geometry of an item's children in order to correctly size the item."

    However the output of a console log is:


  • The best I can find is this:

    // 25 is a fudge value
    height: contentItem.childrend[0].childrenRect.height + 25

    This seems to expand the TreeView to the appropriate size.

  • Well, this is a mixed bag. If I use this and then scroll a listview that contains the treeview it causes the value to glitch out and start reporting different numbers. I suspect items are being dismissed in the background to save resources and being recreated. It may also be related to having multiple treeviews being scrolled over. Like if one it no longer visible it gets disabled. Not quite sure.

  • I have to say, that with all this effort to get treeview to behave it is not really doing what I want anyway. If you give a path to the QFileSystemModel and then hand this to the tree view it forces navigation of the entire path to get to the target directory:

    This is really annoying. I think with the problems I am having I may have to rewrite TreeView and hopefully not have to rewrite QFileSystemModel. I am just not sure where the path problem is yet. Argh!

Log in to reply