Ale*_*nko 6 c++ layout qml qt5
我试图围绕ColumnLayout创建一个滚动视图,不幸的是我当前的代码不起作用.我知道ListView,但在我的情况下,我需要创建可滚动的布局,因为它将包含异构元素.
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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这呈现给了这(显然不是我想要的):

有两个问题:
我究竟做错了什么?
我会使用普通列并通过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"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的情况下,root只是父母的id.希望这可以帮助!
小智 6
我这边也有同样的问题。这对我有用:
ScrollView {
width: parent.width
height : parent.height
contentWidth: column.width // The important part
contentHeight: column.height // Same
clip : true // Prevent drawing column outside the scrollview borders
Column {
id: column
width: parent.width
// Your items here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6101 次 |
| 最近记录: |