Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ListView jumps to beginning after setContextProperty() and positionViewAtIndex()



  • In my QML ListView model can have many different changes and therefore I reset it's context property after each change. To keep view position on the list I used non-obvious solution. When flicking movement stops ListView sends signal

    Item {
        id: iItem
        signal sendIndex(int index)
        function getIndex( index ){ lView.positionViewAtIndex( index, ListView.Beginning ) }
    ...
        ListView {
            id: iView
    ...
            onMovementEnded: lItem.sendIndex( indexAt(1,contentY) )
    ...
    

    In C++ code I get this signal to slot and store index. Later when model calls setContextProperty() for this list root object - it sends signal with stored index to this object. This signal reaches function getIndex( index ) and changes view position. All this works fine in several cases except one. When model only reorders internally: no new items appear, no any items removed, just only one item changes and model sorts respectively - then view first draws properly with stored index first. But after second it suddenly draws list from beginning. In all other cases this does not happen - list draws properly with first item which index was stored. Changed item index before change always is greater and remains greater than first item view index (after sort changed item always goes down in list). And what is most frustrating - when view jumps to beginning - NO onMovementEnded event emits. If only it would happen - I would get signal and restore view position again. But I do not know what is the reason for view jump and which one event or signal to catch.

    Anybody knows what happiness? Why list view jumps to beginning some time after lView.positionViewAtIndex() call? May be this happiness after entire view of model draws (model is big and view is long) - in this case how to catch "end of draw" event?

    All described above appears in Android with Qt 5.9.6. I did not make native Linux app yet - but I will do this tomorrow.



  • May be signal QQuickWidget::statusChanged( QQuickWidget::Ready ) will help. Tomorrow...



  • After call to setContextProperty() with just resorted model - the root object emits statusChanged( QQuickWidget::Ready ) twice. First after first call to setContextProperty() and second after some time without reasonable need. This all looks like a bug.



  • Just opened the bug report.


Log in to reply