The correct way to do this is to first call the scene's event handler, and then check if the mouse event was accepted or ignored by the scene.
Reimplement mousePressEvent in QGraphicsScene like this:
{
// First check if any items on the scene accept the event
if (!event->isAccepted()) {
// Someone clicked outside an item, or on an item that doesn't
// accept mouse events.
}
}
void CustomScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// First check if any items on the scene accept the event
QGraphicsScene::mousePressEvent(event);
if (!event->isAccepted()) {
// Someone clicked outside an item, or on an item that doesn't
// accept mouse events.
}
}
To copy to clipboard, switch view to plain text mode
This is better than checking if there are items at the mouse position with QGraphicsScene::items(), because certain items are transparent for mouse events. Like landscape items, in a game scene.
Bookmarks