Nominate our 2022 Qt Champions!

Having QML TreeView rows that fit contents

  • Hi,
    Is there a way to have rows in a QML TreeView to fit their contents when using itemDelegate or rowDelegate? Basically, I use a custom itemDelegate (Rectangle+Layout+Text+Image) but I cannot predetermine the height of each row as it depends on its contents.


  • I am having the same problem. I would like to have text wrap and have the row height expand correctly to display the text based on the size of parent. if I have '\n' in the display text the row shows half of text from both lines. Is there a way using the delegates to tell the QML Treeview to adjust the height?

  • Moderators

    @dzimiwine For now you can make use of the private properties. Eg.

    TreeView {
       id: tree
       Component.onCompleted: {
           __currentRow = 0;
           var rowheight = tree.__currentRowItem.height

    But note that these are still under development and hence its implementation or the property name itself may change in future.

  • @p3c0
    I can change the row height of a top level item, but I don't see how I can adjust the height for the children. Is there away using one of the delegates to change the row height of a child based it's Role?

  • @p3c0
    Thanks for your reply.
    I am not sure it is going to work as I need to do it for sub items. I will try few things and probably come back to you.

  • This post is deleted!

Log in to reply