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 jumps to beginning after setContextProperty() and positionViewAtIndex()
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 1 Posters 428 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.
  • G Offline
    G Offline
    Gourmet
    wrote on last edited by Gourmet
    #1

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gourmet
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gourmet
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gourmet
          wrote on last edited by
          #4

          Just opened the bug report.

          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