Solved How to prevent a QGraphicsItem from getting mousePressEvent from higher QGraphicsItem?
-
@Niagarer
and in .h its
protected:
virtual void mousePressEvent(QMouseEvent *event) override; -
Ah sorry
its
void QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent * event)the other syntax is for QWidgets
So its other type of event class. else concept should be the same
so just change QMouseEvent to QGraphicsSceneMouseEvent and we
are in business i hope. -
@mrjj
Ah, ok, I see, let me try... -
@mrjj
It doesn't work... the mousePressEvent gets not executed... hm...
Or I am stupid, I don't know... -
@Niagarer
you are not stupid. :)make sure you have
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
in h.notice the override.
it should say if its not really overriding it -
@mrjj
Yes, that is exactely what I wrote...
Oh wait... -
@Niagarer
hmm hmm
And no erros or warning ? -
-
@mrjj
Wooow, I just wrote mouseMoveEvent 2 minutes ago, copy and paste mistake.
Yes it works now, so the actual thing was the usage of QGraphicsSceneMouseEvent. And yes, the mousePressEvent of the item behind it, does not get triggered, wonderful.
Wonderful, thank you very much!To sum it up:
#include <QGraphicsSceneMouseEvent> void myQGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event){ QGraphicsItem::mousePressEvent(event); // call base // do stuff event->accept(); say its handled, so the items behind dont get the mouseClick }
@mrjj said in How to prevent a QGraphicsItem from getting mousePressEvent from higher QGraphicsItem?:
This goes for all Event type functions
if you say
event->accept();
you say "i handled it" and Qt will not try to give it to others -
Oh sorry, it was my bad, i pasted the wrong one before. I guess u copied it and
like me didnt see it was move and not press :)
Good it works !This goes for all Event type functions
if you say
event->accept();
you say "i handled it" and Qt will not try to give it to others