我正在尝试围绕ColumnLayout创建滚动视图,不幸的是我的当前代码不起作用。我知道ListView,但就我而言,我需要创建可滚动的Layout,因为它将包含异构元素。
ApplicationWindow {
id: mainwindow
title: qsTr("Hello World")
width: 300
height: 300
visible: true
ScrollView {
anchors.fill: parent
ColumnLayout {
width: mainwindow.width
Image {
anchors.bottomMargin: 10
source: "img/button.jpg"
width: parent.width
height: 400
}
Image {
source: "img/button.jpg"
width: parent.width
height: 500
}
}
}
}
这导致了这一点(这显然不是我想要的):
有两个问题:
我究竟做错了什么?
我将使用一个普通列,并通过id直接访问所需的width属性。据我了解,这些容器元素根据其内容来测量其大小,这可能就是设置ColumnLayouts宽度无效的原因。
这对我有用:
ScrollView
{
anchors.fill: parent
Column {
Repeater {
model: 4;
delegate: Item {
width: root.width;
height: image.sourceSize.height;
Image {
id: image;
anchors.centerIn: parent;
width: parent.width;
fillMode: Image.Stretch;
source: "img" + (index+1) + ".png"
}
}
}
}
}
在我的情况下,根仅是父母的ID。希望这可以帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句