Unsolved QGraphicsScene::setSelectionArea seems to ignore custom GraphicsItems in view
-
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 typeCurve
. 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 thescene->selectedItems()
(the pointers are0x2d480ed0
and0x2d480ad0
) which are also in line 2, representingscene->selectedItems()
.My issue is: The rectangle drawn after
setSelectionArea
was called only covered theQGraphicsEllipseItem
. This seems like a bug to me, as it ought to cover all the items inscene->selectedItems()
, should it not?I can work around this by implementing my own
setSelectionArea
or something to include allQGraphicsItems
, 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.
-
Moving this to bug reports. Until I do, I'm leaving this unsolved in case anyone wants to respond. Sorry, new to this, so I didn't know.
-
@Mad_Maniac
Hi
If you post a link to the bug report here, people can vote for this issue.