You can install an event filter on the QGraphicsItems. In particular, you'll want to use this function: -
void QGraphicsItem::installSceneEventFilter(QGraphicsItem * filterItem);
As the Qt documentation states, here's an example of its usage: -
QGraphicsScene scene;
QGraphicsEllipseItem *ellipse = scene.addEllipse(QRectF(-10, -10, 20, 20));
QGraphicsLineItem *line = scene.addLine(QLineF(-10, -10, 20, 20));
line->installSceneEventFilter(ellipse);
// line's events are filtered by ellipse's sceneEventFilter() function.
ellipse->installSceneEventFilter(line);
// ellipse's events are filtered by line's sceneEventFilter() function.
Based on this, create a class, derived from QGraphicsItem, which can receive the events first. For each item you add to the scene, call the installSceneEventFilter: -
mySceneEventItem.installSceneEventFilter(pGraphicsItem);
Next, your eventFilter object overrides the function: -
bool QGraphicsItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
{
if(event->type() == QEvent::GraphicsSceneMove)
{
emit my_item_changed(watched); // signal that the item was moved
}
return false; // pass the event to the original target item
}
This allows you to check events and handle those that you're interested in. If you return false from sceneEventFilter, the event will be passed onto the original object, after you've dealt with it; returning true will block the event from being passed on.