qml - 如何对 QML TreeView 中的行应用不同的样式
问题描述
我需要在 QML 中显示树视图。数据看起来像这样
title item
sub item
sub item
title item
sub item
我需要做的是在所有标题项目而不是子项目旁边显示一个复选框
我已经设法为所有项目设置了一个复选框,但我不知道如何只为标题项目显示它
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
TreeView {
model: myModel
alternatingRowColors: false
anchors.fill: parent
headerDelegate: {
visible: false
}
TableViewColumn {
title: "Name"
role: "display"
width: 300
}
itemDelegate: Item {
id: itemId
CheckBox {
anchors.verticalCenter: parent.verticalCenter
text: styleData.value.text
}
}
}
}
解决方案
对于任何有兴趣的人,我认为这是这样做的正确方法
itemDelegate: Loader {
property string imageSource: model.imageSource
property string title: model.title
property int fontSize: model.fontSize
property string subText: model.subText
source: {
switch (model.type)
{
case 0:
return "TopLevelComponent.qml"
case 1:
return "StationComponent.qml"
case 2:
return "StationComponent.qml"
}
推荐阅读
- mysql - 一致性读取会导致 Lock Timeout Excedeed 错误吗?
- arrays - Perl - 对复杂数据结构进行排序
- dotnetnuke - 如何使用 FontAwesome 5 在 2sxc 中配置字体图标选择器?
- javascript - 将反应组件添加到 html 元素
- reactjs - `childMarkdownRemark` 未出现在 GraphiQL 架构中
- node.js - Mongoose .find() = 查询,但查询何时完成?
- python - 如何使用 Python 基于正则表达式分隔字符串
- javascript - 如何使用命令 userinfo (discord bots) 获取用户 ID
- asp.net-mvc - 在 Web API 中启用了 Asp.Net MVC CORS,但不再发送标头
- javascript - 将 Z 坐标放在 Highcharts 工具提示中