如何在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
        }
    }
}