Custom QGraphicsItem mousePressEvent for single click works only when double click [Solved]
I have the following mousePressEvent, it's works fine but only when double clicking the mouse, I want it to work only when single click on the mouse button.
@void MapNode::mousePressEvent(QGraphicsSceneMouseEvent *event)
isClicked *= -1;
I found a solution for this:
I have a mousePressEvent in the parent of my custom QGraphicsItem, which is a custom QGraphicsView, only needed to add inside the custom QGraphicsView mousePressEvent the following line of code in the beginning of the method:
so now single click works fine, probably the event on the parent blocked the event on the child.
Every time that you override those virtual methods (mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent...) you need to call base class metod too.
And you don't need to call:
So, works with:
bq. The view receives input events from the keyboard and mouse, and translates these to scene events (converting the coordinates used to scene coordinates where appropriate), before sending the events to the visualized scene.