C++ (Qt)void MyScene::mousePressEvent (QGraphicsSceneMouseEvent * event){ QGraphicsItem *item = itemAt(event->pos()); if (item && item->type() == ...) { QGraphicsScene::mousePressEvent(event); } else { ... event->accept(); }}
C++ (Qt)auto l = items( event->pos(), Qt::ContainsItemShape );QGraphicsItem* item = !l.isEmpty() ? l.first() : nullptr;
void MyScene::mousePressEvent (QGraphicsSceneMouseEvent * event){ QGraphicsItem *item = itemAt(event->pos()); if (item) { ... event->accept(); } else { QGraphicsScene::mousePressEvent(event); }}
auto l = items( event->pos(), Qt::ContainsItemShape );QGraphicsItem* item = !l.isEmpty() ? l.first() : nullptr;
QList<QGraphicsItem*> l = items(event->pos(), Qt::ContainsItemShape, Qt::DescendingOrder ); QGraphicsItem* item = !l.isEmpty() ? l.first() : NULL;
QGraphicsItem *item = itemAt(event->pos()); if (item) { ... event->accept(); } else { QGraphicsScene::mousePressEvent(event); }}
C++ (Qt)QGraphicsItem* item = 0;for( int i = 0; i < l.count(); i++ ) if( l.at( i )->type() != QGraphicsLineItem::Type ) { item = l.at( i ); break; }