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



  • 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?


  • Moderators

    Hi,

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



  • 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.


  • Moderators

    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 ?



  • 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")



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.