[英]Qml ListView empty rows placeholders like in TableView
With help of Qt guys, got a nice solution (this code is inside of ListView which is inside of ScrollView):在 Qt 的帮助下,得到了一个很好的解决方案(这段代码在 ListView 里面,它在 ScrollView 里面):
Component {
id: rectComp
Rectangle {
id: rowHeaderRect
height: 50
color: rowIndex % 2 == 0 ? Theme.rowColor : Theme.altRowColor
}
}
Column {
id: rowfiller
Loader {
id: rowSizeItem
sourceComponent: rectComp
visible: false
}
property int rowHeight: rowSizeItem.implicitHeight
property int paddedRowCount: height/rowHeight
y: listview.contentHeight - listview.contentY + listview.originY
width: parent.width
visible: true
height: scrollview.viewport.height - listview.contentHeight
Repeater {
model: visible ? parent.paddedRowCount : 0
Loader {
property int rowIndex: index
width: rowfiller.width
height: rowfiller.rowHeight
sourceComponent: rectComp;
}
}
}
A very simple approach.一个非常简单的方法。
First, define the item height:首先,定义项目高度:
property int itemHeight: 40
Then, on the ListView
:然后,在
ListView
:
Component.onCompleted: {
var numItems = mainForm.height / itemHeight
for(var i=0; i < numItems; i++) {
listView1.model.append({})
}
}
where mainForm
is the parent of listview1
.其中
mainForm
是listview1
的父级。
For the empty rows to display correctly you could check for the existence of the item property, ie:为了正确显示空行,您可以检查 item 属性是否存在,即:
color: colorCode ? colorCode : "white"
text: name ? name : ""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.