Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-99131

ListView places old `currentItem` under new `currentItem` during a model append

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Fixed
    • Affects Version/s: 5.15.7, 6.2.2
    • Fix Version/s: 5.15.8, 6.2.3
    • Labels:
      None
    • Environment:
      Ubuntu 20.04 (x86-64)
    • Commits:
      0494b3a98c781abdde321d82b3deb0dc38e985b8 3818ec46b152dce97ebe88c9b1cecde8573e0a13

      Description

      When a ListView has more items than it can fit in its viewport, it keeps the `currentItem` around even if it is not in the viewport.  But if that item is near the end, a new item is added to the end of the model, and that new item is set as the `currentIndex`, the old `currentItem` is erroneously moved to the new `currentItem` location (and becomes hidden underneath it).

       

      I tested 3 versions of Qt.  5.15.7 and 6.2.2 have this issue.  5.15.1 does not have this issue.  I've attached a simple test program that can reproduce this error.

      To reproduce (generic steps)

      1. Have a ListView with more items than it can visibly fit.
      2. Scroll to the end.
      3. Select the second from the last item.
      4. Scroll to the beginning.
      5. Click a button that adds a new item to the end of the ListView's model and set that new index as the current index.
      6. The previously selected item will appear to be gone (but it is just underneath the last item)

      To reproduce (attached example program)

      1. Scroll to the end.
      2. Select `Item 18`.  (screenshot attached)
      3. Scroll to the beginning.
      4. Click `New Item`.
      5. `Item 18` is now hidden under `Item 20`.  (screenshot attached)

      Following those steps with the attached program will result in this message in the console (full console is also attached):

      >:( Delegate for index 18 is at the wrong location (x = 4000)

      (speculation) This seems to be a case that because the ListView is also creating a new item because of the appended item, it calculates a bad `x` value for what was the `currentItem` before setting `currentItem` to the new item.

        Attachments

        1. console.txt
          3 kB
        2. listViewBug.zip
          7 kB
        3. step_2.png
          step_2.png
          11 kB
        4. step_5.png
          step_5.png
          11 kB

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              smd Jan Arve
              Reporter:
              solim Mark Domschot
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes