有没有办法在ListView
中隐藏某些项?
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480
visible: true
ListView {
anchors.fill: parent
model: ListModel {
ListElement { color: "red"; visible: true}
ListElement { color: "green"; visible: false}
ListElement { color: "blue"; visible: true}
}
delegate: Rectangle {
width: parent.width
height: model.visible ? 30 : 0
color: model.color
visible: model.visible
enabled: model.visible
}
}
}
如果ListView可以忽略不可见的Item
的height
,那么上面的解决方案将是好的。
手动将height
设置为0
会影响性能,因此我需要一个更好的解决方案。你能帮我吗?
ListView
只在需要时创建代理,即只有可见的代理被创建,并且这取决于当前视口。你可以同时显示10万个代理吗? - BaCaRoZzo