qt - 如何在qml中使用中继器连续显示图像?
问题描述
所以我必须在我的页面上显示 9 张图像,所以我使用了中继器,但问题是我想连续显示图像,但输出却显示在一列中。我正在使用 qml 开发移动应用程序。那么有人可以建议我如何使用 qml 以行格式显示它吗?
这是我的代码
ColumnLayout {
spacing: 10
clip:true
Repeater{
model: 9
Row{
id:icons
spacing:30
Layout.alignment: Qt.AlignHCenter
Image {
id: img1
source:"path to images"
height: 50
width:50
}
}
}
}
解决方案
替换ColumnLayout
为RowLayout
并使用modelData
属性。
RowLayout {
anchors.fill: parent
Repeater{
model: ["img1.png", "img2.png"]
Image {
Layout.preferredWidth: 50
Layout.preferredHeight: 50
source: modelData
}
}
}
推荐阅读
- python - pygame返回转换后的表面,set_alpha不起作用
- python - 如何在 Django 中创建多个模型对象
- kendo-ui - 我想更改 Kendo Scheduler 中的背景颜色
- amazon-iam - AWS CDK - 如何将访问密钥密钥和密钥 ID 作为环境参数传递给容器
- javascript - ajax设置后类属性未定义
- xamarin - 如何检查 Xamarin.Forms 中 IsPropertyChanged 方法中可绑定属性的设置?
- nuget - 恢复nuget包冲突
- mysql - 如何优化具有多对多关系的 mysql COUNT() 查询(通过第三个表)
- flutter - Flutter-Web:url_launcher 链接小部件鼠标悬停
- javascript - 当包有声明文件时,如何将 Javascript 库导入 Typescript