The content of ListView disappears when scrolling ScrollView
Solved
QML and Qt Quick
-
I've got a ScrollView and LisView inside. The model for the ListView is RowLayout with two SpinBoxes inside. I also have a button, that adds rows in my ListView. The problem is the following:
I add too many rows to the ListView( at least 20 ) and change the current value of one of the SpinBoxes(in order to make it differ from the initial) in first rows. And when I am scrolling to the bottom and then to the top I'm loosing the content of the changed rows(like they are resetting). Code:import QtQuick 2.0 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.3 ApplicationWindow { id: window width: 500; height: 500 visible: true ScrollView { id: scrollView width: window.width height: window.height * 2 / 3 ListView { id: listView x: 0 y: -495 width: 303 height: 1795 interactive: true model: listModel delegate: listDelegate } ListModel { id: listModel ListElement { index: 0 } } Component { id: listDelegate RowLayout { id: rowLayout visible: true width: scrollView.width * 0.95 Label { Layout.fillHeight: true Layout.fillWidth: true text: (index + 1) + ")" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } SpinBox { id: spinBoxCorner Layout.fillHeight: true Layout.fillWidth: true to: 32 } SpinBox { id: spinBoxStep Layout.fillHeight: true Layout.fillWidth: true to: 500 stepSize: 1 value: 0 } } } } Button { id: button x: 59 y: 403 text: qsTr("add") onClicked: listModel.append({"index" : listModel.count}) } Button { id: button1 x: 306 y: 403 text: qsTr("remove") onClicked: listModel.remove(listModel.count - 1) } }
Thanks in advance!
-
Sorry for disturbing. This is the answer:
https://doc.qt.io/qt-5/qml-qtquick-listview.html#cacheBuffer-prop