QML TreeView-更改展开图标的位置

时间:2018-12-07 17:11:55

标签: qt treeview qml

我目前正在尝试更改 QML TreeView 的布局,以使展开图标(您必须单击以显示或隐藏的箭头或三角形)儿童元素)。

我尝试将图标锚定在TreeView的右侧,但是由于某种原因,它无法正常工作,尽管一切正常,它仍保留在左侧。你有什么提示吗?

非常感谢!

TreeView {
    id: treeView
    anchors.fill: parent
    model: treeModResult

    style: TreeViewStyle {
        branchDelegate: Rectangle {
            width: 15; height: 15
            color: "#00000000"
            anchors.right: treeView.right

            Image {
                id: expandArrow
                source: styleData.isExpanded ? "qrc:/img/icn_arrow_top.svg" : "qrc:/img/icn_arrow_bottom.svg"
                sourceSize.width: parent.width
                sourceSize.height: parent.height
            }

            ColorOverlay {
                anchors.fill: expandArrow
                source: expandArrow
                color: "#293147"
            }
        }
    }
}

更新

这是我目前拥有的:

enter image description here

这就是我想要的:

enter image description here

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我想出了以下解决方案,因为锚定对我也不起作用..

style: TreeViewStyle {
        branchDelegate: Rectangle{
            id: expandIcon
            x: control.width - width

control.width 表示树状视图的宽度。