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. ListView item disappears (not repainted) after scrolling outside visible area
Forum Update on Monday, May 27th 2025

ListView item disappears (not repainted) after scrolling outside visible area

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 3.9k 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.
  • R Offline
    R Offline
    Rizzer
    wrote on last edited by
    #1

    I have a customised QStandardItemModel which I access in a QML ListView. My ListView is exhibiting this pathology: if I scroll the items up (by touch, on an Android device) such that the top items move up past the visible area, then when they slide back down into the visible area, the items come back appearing blank. But they are still there, since they are restored if I switch to a different page and back. cacheBuffer does not seem to make any difference.

    I imagine something is wrong my with delegate, but I can't see what. The problem is likely in my code somewhere, since if I try to reproduce with a simplified example then the ListView does work fine. That unhelpfully means I can't really provide sample code to show the problem.

    Does anyone have experience with this kind of problem?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      With the "simplified example" do you mean you modified the model only and keeping the ListView with delegate in both cases unmodified ?

      157

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rizzer
        wrote on last edited by
        #3

        Simplified both in the model in C++, defining only one role, and in the Delegate, using one role-field (in one Text item) instead of two.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Well it would be tough without seeing the code, we will need to keep on guessing the problem. Have you reimplemented rowCount(const QModelIndex &parent) ? Or are you adding all the items may be in a for loop ?

          157

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rizzer
            wrote on last edited by
            #5

            it would be tough without seeing the code

            Yeah, I appreciate the trouble :)

            Have you reimplemented rowCount(const QModelIndex &parent) ?

            No, I keep the default one from QStandardItemModel.

            Or are you adding all the items may be in a for loop ?

            Initially they're added one by one in a set of consecutive calls to appendRow(item). My simplified version used a for loop. The model is set up before the QML files are loaded by engine.load("main.qml")

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rizzer
              wrote on last edited by
              #6

              The problem seems to arise from using a Rectangle to encapsulate the Delegates. I want the extra layout provided inside a Rectangle component in order to use different items inside the Delegate to display different fields.

              This QML code seems sufficient to reproduce the problem:
              @ ListModel {
              id: longModel

                      Component.onCompleted: {
                          for ( var i=1; i<=100; i++ )
                              append({"testName": i})
                      }
                  }
              
              
                  ListView {
                      anchors.fill: parent
                          id: listView
                          model: longModel
              
                      delegate:
                          Rectangle {
                          height: textComponent.height*2
                          width: parent.width
              
                          Text {
                              id: textComponent
                              text: testName
                          }
                      }
                  }
              

              @

              A workaround is to place the Text component inside a RowLayout instead of a Rectangle. Another workaround is to place the Rectangle inside an Item (i.e. use delegate: Item{ Rectangle{ Text{} }})

              But nevertheless, shouldn't it be possible to successfully use a Delegate with Text inside Rectangle, as done in the sample code?

              1 Reply Last reply
              0

              • Login

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