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

QGraphicsScenePrivate::movingItemsInitialPositions becomes unreliable after ungrabMouse if mouse is still pressed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15, 6.6
    • Widgets: GraphicsView
    • None
    • All

    Description

      I was attempting to create a sort of "move-undo" that, after pressing the Escape key, moves it back to the original position (before the movement began), then ignores further mouse movements until an item is pressed again.

      I discovered that when one or more items are being moved with the mouse and ungrabMouse() is called before releasing the mouse button that caused it, trying to move a non previously selected item becomes unreliable, completely resetting the position of the item to QPointF(0, 0) of its parent.

      The steps to reproduce the problem are the following:

      1. add 2 or more movable graphics items;
      2. start moving one of them;
      3. while the mouse button is still pressed call ungrabMouse (for instance, after a key press);
      4. release the mouse button and try to move another, not previously moved/selected item

      The result is that newly pressed/selected items are instantly moved to 0, 0 of their parent (or the scene).

      I was able to track down the issue to the fact that QGraphicsScenePrivate::movingItemsInitialPositions is not cleared as it normally happens when the mouse button is released: when mouseMoveEvent is called from a different selected item, movingItemsInitialPosition is not empty, so it is not updated with the new selection and does not contain the new items (including the new grabber), so the final item->setPos()  will use an empty QPointF because it doesn't find the item in the map.

      I think that clearing up that map in ungrabMouse might be sufficient, but I am not completely sure.

      I'm attaching a simple example in PySide2. Note the issue happens with simple movable items, but I made items selectable so that multiple selections will show that movements of previously moved items properly follow the existing map.

      Attachments

        For Gerrit Dashboard: QTBUG-118449
        # Subject Branch Project Status CR V

        Activity

          People

            bibr Andreas Aardal Hanssen
            musicamante Maurizio Berti
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change