【问题标题】:How to set gradient to QML TreeView background?如何将渐变设置为 QML TreeView 背景?
【发布时间】:2018-07-11 15:36:57
【问题描述】:

我试图将 TreeView 的背景更改为渐变色,但我找不到任何方法。

TreeViewStyle 中,唯一与背景相关的属性是:“backgroundColor”,但只接收color 类型。

那么,是否可以将背景设置为渐变?

【问题讨论】:

    标签: qt treeview qml


    【解决方案1】:

    演示:

    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})
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-27
      • 1970-01-01
      • 2019-02-22
      • 2015-09-01
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      相关资源
      最近更新 更多