有没有办法隐藏 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
s' height
,上面的解决方案会很好 .
手动将 height
设置为 0
对性能不利,因此我需要更好的解决方案 . 你可以帮帮我吗?
2 回答
我希望这能解决问题 . 对于像我这样的初学者来说,解决这个问题有助于更多地理解qml .
您可以使用QSortFilterProxyModel过滤值: