Details
-
Bug
-
Resolution: Duplicate
-
P1: Critical
-
6.3.0 Alpha
-
None
-
-
b994c7ffa (dev), f9efa3469 (6.5)
Description
I'm not quite sure if this is a bug, or by design.
But if a delegate has its geometry (width, height or visibility) changed post-initialization,
then the QQuickListViewPrivate::layoutVisibleItems function wont be called to properly lay out the delegates again.
The first time that QQuickListViewPrivate::layoutVisibleItems is called, it will usually be from the window expose event.
One way to reproduce the problem, would be to run the following code a few times:
import QtQuick import QtQuick.Controls Window { width: 640 height: 480 visible: true Rectangle { id: rect property string sectionProperty: "section" property int sectionPositioning: ViewSection.InlineLabels anchors.fill: parent color: "#FFFFFF" resources: [ Component { id: myDelegate Text { id: myDelegateText objectName: model.title width: parent.width height: 40 text: "NormalDelegate: " + model.title visible: model.isVisible verticalAlignment: Text.AlignVCenter } } ] ListView { id: list objectName: "list" anchors.fill: parent clip: true model: ListModel { ListElement { title: "element1" isVisible: true section: "section1" } ListElement { title: "element2" isVisible: true section: "section1" } ListElement { title: "element3" isVisible: true section: "section2" } ListElement { title: "element4" isVisible: true section: "section2" } } delegate: myDelegate section.property: "section" section.criteria: ViewSection.FullString section.delegate: Component { Text { id: sectionDelegate objectName: section visible: false onVisibleChanged: console.log("visible: " + visible) width: parent.width height: visible ? 48 : 0 text: "Section delegate: " + section verticalAlignment: Text.AlignVCenter elide: Text.ElideMiddle Component.onCompleted: function(){ Qt.callLater(function(){ let newValue = true console.log("setting visibility " + newValue) sectionDelegate.visible = newValue }) } } } } } }
You should notice that the delegates will overlap occasionally. Depending on whether the visibility for the section delegates are set to true before or after the window expose event causes layoutVisibleItems to be called.
The potential bug can also be reproduced with this code:
import QtQuick import QtQuick.Controls Window { width: 640 height: 480 visible: true Rectangle { id: rect property string sectionProperty: "section" property int sectionPositioning: ViewSection.InlineLabels anchors.fill: parent color: "#FFFFFF" resources: [ Component { id: myDelegate Text { id: myDelegateText objectName: model.title width: parent.width height: 40 text: "NormalDelegate: " + model.title visible: model.isVisible verticalAlignment: Text.AlignVCenter MouseArea { anchors.fill: parent onClicked: function(){ parent.height = 60 } } } } ] ListView { id: list objectName: "list" anchors.fill: parent clip: true model: ListModel { ListElement { title: "element1" isVisible: true section: "section1" } ListElement { title: "element2" isVisible: true section: "section1" } ListElement { title: "element3" isVisible: true section: "section2" } ListElement { title: "element4" isVisible: true section: "section2" } } delegate: myDelegate section.property: "section" section.criteria: ViewSection.FullString section.delegate: Component { Text { id: sectionDelegate objectName: section visible: true width: parent.width height: visible ? 48 : 0 text: "Section delegate: " + section verticalAlignment: Text.AlignVCenter elide: Text.ElideMiddle MouseArea { anchors.fill: parent onClicked: function(){ parent.height = 68 } } } } } } }
If you click on a delegate, the delegate will have its height increased by 20 pixels.
Normal delegates will cause a layout update, while a section delegate won't.