Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
None
-
5.14.0 RC2
-
None
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())
}}}
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.