AdamDavidson
AdamDavidson

Reputation: 3

Passing event from QGraphicsScene to QGraphicsItem in C++ with Qt

I have a base class extending QGraphicsScene...

class BaseScene : public QGraphicsScene

in that class is the protected event...

void BaseScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)

There are some user clicks where I need to pass the event on to the QGraphicsItem inside the QGraphicsScene, as the QGraphicsItem also contains a 'mousePressEvent'.

How can I propergate down events of my choosing from the QGprahicsScene to a specific QGraphicsItem?.

Thank you.

Upvotes: 0

Views: 1771

Answers (1)

zkunov
zkunov

Reputation: 3412

In your reimplemented mousePressEvent() add:

QGraphicsScene::mousePressEvent(mouseEvent);

This will call the default implementation : "The default implementation depends on the state of the scene. If there is a mouse grabber item, then the event is sent to the mouse grabber. Otherwise, it is forwarded to the topmost item that accepts mouse events at the scene position from the event, and that item promptly becomes the mouse grabber item."

Hope this helps

Upvotes: 1

Related Questions