0

I have a GridView (LtoR flow) that is sorted dynamically via a QSortFilterProxyModel. The GridView has 100 tiles at all times. I scroll down until visibleArea.yPosition is at e.g. 0.7 (70%). I wait for the model to update, causing the tiles to reorder. Since the nr of tiles doesn't change, I'd expect visibleArea.yPosition to stay at 0.7 - but it doesn't. It changes to other values (I can't really figure out a pattern). Likewise, originY changes automatically from 0 to higher numbers.

This means, for example, that if I scroll to the end of the grid and wait for a bit, I might actually be looking at the beginning of the grid after a while, due to these changes. I tried setting visibleArea.yPosition to the value it had at the end of the last user interaction whenever the data changes, but QML tells me that the property is read-only.

Why does the scroll position of the GridView jump around like this, and how can I stop it?

relevant QML code:

GridView {
    clip: true
    model: stateUiItemModel
    delegate: myDelegate
    anchors.top: commandArea.bottom
    anchors.left: parent.left
    anchors.right: parent.right
    anchors.bottom: bottomArea.top
    cellWidth: itemWidth
    cellHeight: itemHeight
    transformOrigin: Item.TopLeft
    cacheBuffer: 100

    visibleArea.onYPositionChanged: {
        console.log("ypos " + visibleArea.yPosition + " oy " + originY);
    }
}

output:

qml: ypos 0.7253333333333334 oy 0 // manually scrolled to this point
qml: dynamic sort enabled  // from here on GridView repaints with changed sorted order every 500ms
qml: ypos 0.6586666666666666 oy -200
qml: ypos 0.792 oy -400
qml: ypos 0.7253333333333334 oy -400
qml: ypos 0.6586666666666666 oy -500
qml: ypos 0.792 oy -700
qml: ypos 0.7253333333333334 oy -700
qml: ypos 0.6586666666666666 oy -600
qml: ypos 0.592 oy -500
qml: ypos 0.5253333333333333 oy -400
qml: ypos 0.45866666666666667 oy -300
// ... etc, new values every 500ms
pholz
  • 684
  • 8
  • 19
  • Some code could help understand what's going on here. That being said, [`contentY`](http://doc.qt.io/qt-5/qml-qtquick-flickable.html#contentY-prop) can be used in place of `yPosition` which is indeed read-only. – BaCaRoZzo Jun 17 '15 at 15:48
  • I just added the code. Also, I checked: `contentY` doesn't change, so setting it doesn't make a difference. `contentY` stays the same while `originY` and `visibleArea.yPosition` change, and both cannot be written to... – pholz Jun 17 '15 at 16:35
  • That's quite a strange behavior. – BaCaRoZzo Jun 17 '15 at 17:49
  • Debugging with `move` and `moveDisplaced` animations, it seems that the grid rearranges itself by moving tiles in a strange way: E.g. if you have four rows, the "camera" is looking at the third row, and all tiles from the last row need to be at the beginning, then the last row may just go the top beyond the first row, and the "camera" is now looking at the last row. Performance-wise, it makes sense, but in terms of visual stability, it would be better if after the move all rows would shift down one row so that the "camera" still points to the third row. – pholz Jun 18 '15 at 10:26

0 Answers0