Important: Please read the Qt Code of Conduct -

How to have a larger spacing for root items in a TreeView

  • Hi,

    to emphasize the grouping of the root items in a TreeView I would like to adjust the spacing (or size) of just the root items.

    I tried doing it using the itemDelegate with a larger height based on styleData.depth like this:

        TreeView {
            anchors.fill: parent
            model: theModel
            itemDelegate: Rectangle {
                color: "#00000000"
                height: styleData.depth > 0 ? 20 : 40
                Text {
                    text: styleData.value
            TableViewColumn {
                role: "title"
                title: "Title"
            TableViewColumn {
                role: "summary"
                title: "Summary"

    Unfortunately it seems that the itemDelegate does not have any influence on the height of rows.

    I found that in the rowDelegate I am able to adjust the height. But there is no styleData.depth available.

    Does anyone have an idea how I can achieve this with a TreeView?

  • I just found out how to do this. There is a section.delegate in TreeView which is inherited from the ListView and can be used the same. Through this one can add an extra property to group the items in sections. When you only do this to the root items you can use this to add spaces to the root items.

Log in to reply