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

QGraphicsScene::setSelectionArea seems to ignore custom GraphicsItems in view

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P4: Low
    • Resolution: Unresolved
    • Affects Version/s: 5.14.0 RC2
    • Fix Version/s: None
    • Component/s: Widgets: GraphicsView
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      When I do QGraphicsScene::setSelectionArea, the selection adds the item to the selection (ie. QGraphicsScene::selectedItems shows my custom items) but the selection rectangle doesn't include it. It strictly includes the QGraphicsEllipseItem.

      Before selection. The rectangle is a selection rectangle that updates as the mouse is moved. As the mouse is released, setSelectionArea is called on the the rectangle, and the rectangle disappears.

      Note that the curve on the bottom is selectable, and I will show why. Furthermore, it also ends up "selected".

      However, this is what happens after selection:

      As proof of the curve being selected, I had this in my code:
       
      qDebug() << 1 << CurvesSelected << 2 << scene->selectedItems() << 3 << scene->selectionArea();

      And the debugger showed this (line endings added here for readability, since my debugger wraps the text):
       
      {{1 QSet(QGraphicsItem(0x2d480ed0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable)), QGraphicsItem(0x2d480ad0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable)))
      2 (QGraphicsItem(0x27ddd8e8, pos=0,0, z=20, flags=(ItemIsSelectable)), QGraphicsItem(0x2d480ed0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable)), QGraphicsItem(0x2d480ad0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable)))
      3 QPainterPath: Element count=5 -> MoveTo(x=-83, y=-53) -> LineTo(x=158, y=-53) -> LineTo(x=158, y=326) -> LineTo(x=-83, y=326) -> LineTo(x=-83, y=-53)
      }}

      Anything in CurvesSelected is of type Curve. It comes from this code:
       
      {{foreach (auto item, scene->selectedItems())

      { Curve *curve = dynamic_cast<Curve *>(item); if (curve) \{CurvesSelected.insert(curve);}

      }}}

      The 2 curves in the drawing are the wavy thing at the bottom, and the thing at the with blue circles at its corners. Since both the contents of the QSet are within the scene->selectedItems() (the pointers are 0x2d480ed0 and 0x2d480ad0) which are also in line 2, representing scene->selectedItems().

      My issue is: The rectangle drawn after setSelectionArea was called only covered the QGraphicsEllipseItem. This seems like a bug to me, as it ought to cover all the items in scene->selectedItems(), should it not?

      I can work around this by implementing my own setSelectionArea or something to include all QGraphicsItems, including ones that are custom defined, but it would've been convenient to use Qt's own member function where possible. And if there's a good reason it doesn't work this way, I'd prefer to know it, (and ideally, that detail should be included in the documentation).

      It's worth noting the debugger clearly shows the items as selectable (and also movable, but that's irrelevant right now), so that's not where the bug is.

        Attachments

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

          Activity

            People

            • Assignee:
              bibr Andreas Aardal Hanssen
              Reporter:
              osamakawish Osama Kawish
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Gerrit Reviews

                There are no open Gerrit changes