qt - QML TreeView - 更改展开图标的位置
问题描述
我目前正在尝试更改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"
}
}
}
}
更新
这是我目前拥有的:
这就是我想要的:
解决方案
我有同样的问题,我想出了以下解决方案,因为锚定对我也不起作用..
style: TreeViewStyle {
branchDelegate: Rectangle{
id: expandIcon
x: control.width - width
control.width 表示树视图的宽度。
推荐阅读
- java - 如何使用 Java 反射将原始类型值分配给方法 args?
- r - Creating two bar charts for one variable in the same plot in R
- elasticsearch - Kibana 时间查询,无日期(使用 KQL)
- python - Python 的 importlib 和检查静态类成员
- javascript - 当函数还可以接受确切的字段名称以作为数组获取时,是否有更好的方法来告诉函数获取所有字段?
- python - Python 类属性装饰器
- django - 从连接到 GCP 中部署的 Django 应用程序的 MongoDB 验证用户时出现数据库错误
- git - 如何在不破坏当前提交的情况下进行 rebase?
- r - 提取两个变量之间的完整文本
- python - 在python中对Elasticsearch的日期字段应用排序