首页 > 解决方案 > 如何在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
             }
           }
        }
    }
  

标签: qtqml

解决方案


替换ColumnLayoutRowLayout并使用modelData属性。

RowLayout {
    anchors.fill: parent

    Repeater{
        model: ["img1.png", "img2.png"]

        Image {
            Layout.preferredWidth: 50
            Layout.preferredHeight: 50
            source: modelData
        }
    }
}

推荐阅读