Is there any way to hide certain item in 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
}
}
}
Solution above would be good if only ListView could ignore invisible Item
s' height
.
Setting height
to 0
manually is bad for performance so I need a better solution. Could you help me?
height: model.visible ? 30 : 0
? – LithiaListView
just creates delegates on demand, i.e. only the visible delegates are created and that's dependent on the current viewport. Can you show simultaneously 100K delegates? – LithiaListView
implementation changed in the last releases and I think that it can be a reason for the observed change. For C++ models tuning thedata()
can help. In the QML site using a top-levelItem
in the delegate vs. aRectangle
, limit the state information in the delegate as well as avoid painting the background can improve performances. Tips may still vary a lot, depending on the model, the Qt version, tough ground. Btw, flagged as duplicate. – LithiaListView
a little bit. UsingLoader
s does not help either. Now, if you remove the hack in this example it runs smoothly. it's like it is accounting the presence of the missing delegate for scrolling the view. Asking the mailing list could definitely help. – Lithia