Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.0
-
None
Description
I have observed the following, somehow strange behaviour:
I am using a ListView to render some items, i.e. I have a model and a delegate defined for this. In addition, I am using a header and footer in the view, to render additional meta information. In the concrete app where I initially observed this behaviour, I have some interactive components in the header and footer, which can change their height while the user interacts with them (most notably, by entering multi-line text). As soon as such a change of the header height happens and the list view is otherwise "empty" (i.e. the model currently holds zero items), the view is positioned back at the beginning of the list.
I managed to break this down into a small example:
import QtQuick 2.12 import QtQuick.Controls 2.5 ApplicationWindow { width: 640 height: 480 visible: true title: qsTr("Scroll") ScrollView { anchors.fill: parent ListView { id: listView width: parent.width model: 100 delegate: ItemDelegate { text: "Item " + (index + 1) width: listView.width } header: Column { Button { text: qsTr("Toggle List View Items") onClicked: if (listView.model === 0) { listView.model = 100; } else { listView.model = 0; } } Item { id: spacer property int foo: 1 width: 1 height: (foo % 2 == 0) ? 100 : 150 Timer { interval: 2000 repeat: true running: true onTriggered: spacer.foo += 1 } } } footer: Item { height: 3000 width: parent.width TextField { width: parent.width placeholderText: qsTr("Write something here") } } } } }
Here, I have a header which changes its height every two seconds. By default, the list view contains some items, hence, everything behaves fine. However, by clicking the button, the list is emptied. Afterwards, when scrolling down, the view will reset the position as soon as the header height changes again.
I know that this rather might be a corner case, but would be cool if this still could be fixed