Qt 带listview的可滚动页面
我有一个名为page2.qml的文件,如下所示Qt 带listview的可滚动页面,qt,qml,qt5,qtquickcontrols2,Qt,Qml,Qt5,Qtquickcontrols2,我有一个名为page2.qml的文件,如下所示 Page { id: page Rectangle { id: container anchors.fill: parent width: parent.width * 0.8 Rectangle { id: title anchors.top: pare
Page {
id: page
Rectangle {
id: container
anchors.fill: parent
width: parent.width * 0.8
Rectangle {
id: title
anchors.top: parent.top
width: parent.width
height: 50
color: "salmon"
}
ListView {
id: listView
currentIndex: -1
anchors.top: title.bottom
anchors.bottom: parent.bottom
delegate: Rectangle {
height: 20
width: 100
border.color: "red"
color: "pink"
Text {
text: model.index
}
}
model: 100
}
}
}
结果如下图所示:
由于listview包含100项,如何使整个页面可滚动?我可以只使listview可滚动,但不能使整个页面可滚动。如果您不需要
listview
可滚动,但整个容器需要滚动,您可以使用转发器
将其放在列中,并用Flickable
包装:
Flickable {
id: container
contentHeight: column.implicitHeight
contentWidth: width
width: parent.width * 0.8
height: parent.height
Column {
id: column
width: parent.width
Rectangle {
id: title
width: parent.width
height: 50
color: "salmon"
}
Repeater {
id: listView
model: 100
delegate: Rectangle {
height: 20
width: 100
border.color: "red"
color: "pink"
Text {
text: model.index
}
}
}
}
}
将您的容器
设置为@PraveenKumar我将容器包装在一个flickable
中,然后设置contentHeight:title.height+listView.contentHeight
,效果非常好,非常感谢。@PraveenKumar请将您的评论作为答案发布,这样我就可以接受它了。下面的示例为您提供了一个更好的答案:)。如果它真的对你有帮助,那就投票吧。