Make QGraphicsItem non interactive with mouse.
-
Hello guys,
I have a QGraphicsView with mouse interaction, mainly a rubberband selection that works just fine. Now I am trying to add a QGraphicsItem(we will name it Box) that will be a container for other QGraphicsItems.
So basically I need to be able to use my rubberband selection inside this Item (Box) as if I was directly in the scene.
I've tried to ignore some events (mousePress/Move/Release) inside the item (Box) hopping that it would then use the scene events. but it doesn't work. Ignore will should send towards the parentItem but the view not being a valid parentItem, my item (Box) doesn't have a parentI just want my item (Box) to be treated as a background color, the item itself will be controlled via handles being children items.
How could I achieve this behaviour ?
Thx :) -
Don't fiddle with events. Just indicate to the item that it should not receive them in the first place:
item->setAcceptedMouseButtons(Qt::NoButton);
-
Then you're doing something else wrong because that's all it takes. Can you compose a minimal code example of what you're doing?
-
Just to make sure you're aware - QGraphicsScene has a built-in rubberband support.
There's no need to implement it manually:view->setDragMode(QGraphicsView::RubberBandDrag)
.