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

Removing items from a qquickcombobox can cause selection corruption

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.4, 5.13.1, 5.15.1, 6.4.2
    • Quick: Controls 2
    • None
    • Linux/X11, macOS

    Description

      Given a Qt Quick Application using a combobox which is attached to a certain model. When removing asynchronously items from the model doesn't update the `currentItemIndex` and causes the combobox to behave like if it was offset from the original order.

      Example:
      Suppose a combo box with the underlying model [A,B,C] that is in the following state:

      A

      B <--- (Current Index = 1)

      C

      which currently has B selected. Suppose then that A is removed from the underlying model. The combo box will now be in the state:

      B

      C <--- (Current Index = 1)

      which will display C as the current selection. I would argue that this is not correct or somewhat surprising. The Current Index should have gone to 0.

      By contrast, suppose we have a combo box in the following state:

      A <--- (Current Index = 0)

      B

      C

      in which A is the current selection. We now suppose that C is removed from the combo box's underlying model. We will have:

      A <--- (Current Index = 0)

      B

      which I would argue is the correct behavior.

      To summarize: when the current index is higher than the index of the element being removed, removing the element changes the current selection in the combo box. When the current index is lower than the index of the element being removed, removing the element does not change the selection in the combo box.

      Within the context of a list model, I believe there might be an expectation that the current selection will "track" its element upon a modification of the underlying model. I suspect that adding an element to the underlying model at an index lower than the current index would likewise cause the selection in the combo box to change.

      Attachments

        1. qtbug-80066.tar
          9 kB
        2. qtbug80066.zip
          3 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            roussinm Maxime Roussin-Bélanger
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes