【问题标题】:QML TreeView - Change position of expand iconQML TreeView - 更改展开图标的位置
【发布时间】:2021-03-19 14:50:00
【问题描述】:

我目前正在尝试更改 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"
            }
        }
    }
}

更新

这是我目前拥有的:

这是我想要的:

【问题讨论】:

  • 我认为如果你能提供 2 张图片 - 你有什么和你想要什么会很好。
  • 谢谢@folibis,我按照你的建议添加了两张图片!

标签: qt treeview qml


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-04
    • 2011-08-06
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多