QML图像列表不可见

时间:2014-09-21 17:16:16

标签: qt list qml qt5

我没有使用QML列表,但我有一个QMLItem需要绘制一些小图块列表。

每当从列表中取出QML Image时,它都是可见的,但不在列表中。 (在任何一种情况下都没有编译时或运行时警告或错误)

显示正常:

Item {
    id : player_health

    Image {
        z:2;
        height: 26;
        width: 19;
        x: 50;
        y: 50;
        source:"resources/gameplay/square_pink.png"
    }
}

不显示(这些图像均不显示):

Item {
    id : player_health

    property list<Image> bars: [
        Image { z:2; height: 26; width: 19; x: 50; y:50; source: "resources/gameplay/square_pink.png"},
        Image { z:2; height: 26; width: 19; x: 50; y:50; source: "resources/gameplay/square_blue.png"}
    ]
}

我希望列表中的图像可见但无法通过列表找到方法。

2 个答案:

答案 0 :(得分:1)

如果您想要美丽的地方放置图片,那么您可以使用简单的定位器RowColumn。例如:

Rectangle {
    x: 8
    y: 250
    width: 320; height: 110
    color: "black"



    Row {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter

        spacing: 5

        Image { width: 100; height: 100; source: "images/earth.png" }
        Image { width: 100; height: 100; source: "images/uranus.png" }

    }
}

答案 1 :(得分:1)

Item {
   id : player_health

   Grid {

     rows: 5; columns: 1; spacing: 10

     Repeater { model: 5
                Image { z:2; height: 26; width: 19; x: 50; y:50; source:"resources/gameplay/square_pink.png" }
     }
 }