Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. The content of ListView disappears when scrolling ScrollView
Forum Update on Monday, May 27th 2025

The content of ListView disappears when scrolling ScrollView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 315 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Verchik
    wrote on last edited by Verchik
    #1

    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!

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Verchik
      wrote on last edited by
      #2

      Sorry for disturbing. This is the answer:
      https://doc.qt.io/qt-5/qml-qtquick-listview.html#cacheBuffer-prop

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved