qt - 如何在 qml 的中继器中使用工具分隔符?
问题描述
Toolseparator 在中继器内不起作用。我需要在每个内容之后的那一行下显示图像和文本,所以为了显示我使用工具分隔符但它不起作用的行,它只是通过仅显示行来覆盖所有内容。这是示例
Repeater {
model: 10
Row {
leftPadding: 10
spacing: 10
Rectangle {
height: 100
width: 200
}
Text {
text: "Username"
}
ToolSeparator {
height: 25
width: 335
orientation: Qt.Horizontal
}
}
}
解决方案
你犯了一些错误,我的朋友。
如果你打算使用
Repeater
——通常你应该在一些定位组件(例如Column
,Row
)中使用它。所以在你的情况下,Repeater
应该在里面Row
。顺便说一句,千万不要忽视查看官方 Qt 文档:Repeater 详细说明;使用 QML 定位器和中继器项目。除此之外,还有很棒的学习资源 QmlBook,例如它的Quick Starter。
如果我对你的理解正确,你会得到这样的东西:
使用此代码作为参考:
Column {
spacing: 10
Repeater {
model: 4
Rectangle {
id: background
height: 50
width: 200
color: "bisque"
Text {
id: text
color: "chocolate"
text: "Username " + modelData
anchors.centerIn: parent
}
Rectangle {
id: separator
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: 5
color: "goldenrod"
}
}
}
}
推荐阅读
- vue.js - 将图像添加到 Vue Select 下拉菜单?
- docker - 仅将 Docker Swarm Manager 节点公开到 Internet。隐藏工作人员(无公共 IP)
- javascript - 在 Electron 的渲染器中导出/定义函数的正确方法
- flutter - 使 BLoC 状态持久化,以便使用 Flutter 制作离线应用程序
- angular - Angular 7,命名路由器插座在延迟加载的模块中不起作用
- java - 转换列表
> 流式传输 - java - 如何解决:“StepsCode 类型的层次结构不一致”问题
- javascript - 引导多选不是一个功能 - 不检查多选脚本
- java - 如何通过 Jenkins 定位特定的 Cucumber 功能文件(自动化测试)?
- actionscript-3 - 在 Adobe AIR windows 应用程序中调整舞台大小