View Full Version : QGraphicsItem: How block input without hack ?

1st May 2018, 09:41
I actually use a hack to block input for one QGraphicsItem but I wonder if it's possible without.
My hack is to set the item selectable and in the itemChange event set selected to false if it changed.
Basically I only just want to block the mouse button press event because I handle the logic of this item in the scene events.
Is it possible without this hack and have the item not selectable ? It works but the selection changed event is then called on this item...
Thank you

1st May 2018, 17:30
What about using QGraphicsItem::setAcceptedMouseButtons() to turn off the response to the button(s)?

1st May 2018, 21:50
What I need is very simple : when the mouse button is pressed this event is not propagated to things behind and not the scene too.
Actually if you click on the item you will have the selection rectangle of the scene, I would not have that happening, just click on the item and nothing happens like a barrier of the mouse event.

6th May 2018, 10:50
Found the solution :

void CEditorNodeConnector::mousePressEvent( QGraphicsSceneMouseEvent* event )
QGraphicsItem::mousePressEvent( event );

7th May 2018, 18:53
Doesn't calling the base class event handler cause the unwanted effects you were trying to avoid? Or have you set the flags to make the item non-editable and non-selectable?

9th May 2018, 15:11
Yes I removed the "selectable" flag and added this mouse filtering.
Yes, it's true, calling the base class can be avoided.