QML:平面不可滚动列表视图
QML: flat non-scrollable list view
我想在一个大的 ScrollView 中有两个列表视图,一个接一个,因为它们的代表略有不同。所以布局是这样的:
不幸的是,ListView 类型也是可滑动的,因此它不会在适合滚动视图的平面列表中显示所有内容。
那么我如何使用 Qt Quick 视图来做到这一点呢?
我尝试了一个技巧:我可以像这样调整列表视图的大小:
ListView {
id: list1
height: contentHeight + spacing * count
model: superModel
delegate: delegate1
}
不幸的是,除了是一个肮脏的 hack 和留下不必要的轻弹来抓住我的点击之外,它并没有真正起作用:内容不适合因为仍然有顶部和底部边距我不知道价值的。
您应该在 ScrollView
中使用带有两个 Repeater
的 ColumnLayout
(如果您愿意,也可以使用 Flickable
)
ScrollView {
contentWidth: width //maybe you don't need this
ColumnLayout {
width: parent.width //maybe you don't need this
Repeater {
model: superModel1
delegate: delegate1
}
Repeater {
model: superModel2
delegate: delegate2
}
}
}
由于您没有显示委托,您可能需要对 implicitHeight
and/or implicitWidth
.
进行微调
我想在一个大的 ScrollView 中有两个列表视图,一个接一个,因为它们的代表略有不同。所以布局是这样的:
不幸的是,ListView 类型也是可滑动的,因此它不会在适合滚动视图的平面列表中显示所有内容。 那么我如何使用 Qt Quick 视图来做到这一点呢?
我尝试了一个技巧:我可以像这样调整列表视图的大小:
ListView {
id: list1
height: contentHeight + spacing * count
model: superModel
delegate: delegate1
}
不幸的是,除了是一个肮脏的 hack 和留下不必要的轻弹来抓住我的点击之外,它并没有真正起作用:内容不适合因为仍然有顶部和底部边距我不知道价值的。
您应该在 ScrollView
中使用带有两个 Repeater
的 ColumnLayout
(如果您愿意,也可以使用 Flickable
)
ScrollView {
contentWidth: width //maybe you don't need this
ColumnLayout {
width: parent.width //maybe you don't need this
Repeater {
model: superModel1
delegate: delegate1
}
Repeater {
model: superModel2
delegate: delegate2
}
}
}
由于您没有显示委托,您可能需要对 implicitHeight
and/or implicitWidth
.