【发布时间】:2018-07-11 15:36:57
【问题描述】:
我试图将 TreeView 的背景更改为渐变色,但我找不到任何方法。
在TreeViewStyle 中,唯一与背景相关的属性是:“backgroundColor”,但只接收color 类型。
那么,是否可以将背景设置为渐变?
【问题讨论】:
我试图将 TreeView 的背景更改为渐变色,但我找不到任何方法。
在TreeViewStyle 中,唯一与背景相关的属性是:“backgroundColor”,但只接收color 类型。
那么,是否可以将背景设置为渐变?
【问题讨论】:
演示:
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})
}
}
【讨论】: