当我在ColumnLayout中放置几个图像时,它们会覆盖自己,我只看到最后一个。
以下是我的代码示例:
Rectangle{
width: parent.width
color: "#00ffffff"
height: 370
ColumnLayout{
width : parent.width
spacing : 0
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: "img/img1.png"
}
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: "img/img2.png"
}
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: "img/img3.png"
}
}
}
您是否知道我如何才能看到3张图片一张接一张?
答案 0 :(得分:1)
这是因为你在执行此操作时强制图像垂直和水平居中:
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: "img/img3.png"
}
如果您希望图像水平居中但同时保持列中的布局,则应从anchors.verticalCenter
组件中删除Image
属性