0
votes

I trying to change the background of a TreeView to a gradient color, but i donĀ“t find anything to do that.

In TreeViewStyle the only property relate to background is: "backgroundColor", but receive only the type color.

So, is it possible to set the background to gradient?

1

1 Answers

1
votes

Demo:

TreeView {
    id: tree
    TableViewColumn {
        title: "Name"
        role: "fileName"
        width: 300
    }
    TableViewColumn {
        title: "Permissions"
        role: "filePermissions"
        width: 100
    }
    model: FolderListModel {}

    Component {
        id: gradient
        LinearGradient {
            gradient: Gradient {
                GradientStop { position: 0.0; color: "white" }
                GradientStop { position: 1.0; color: "black" }
            }
        }
    }

    rowDelegate: Item { } // make rows transparent to show the background

    Component.onCompleted: {
        // the sibling of listView is the background(Rectangle) of TreeView
        var bg = tree.__listView.parent.children[1]
        // set the gradient effect to the background 
        gradient.createObject(bg, {'anchors.fill': bg})
    }
}

enter image description here