[Interest] Reimplementing QGraphicsView::contextMenuEvent blocks other context menus
Richard Kimmel <rdk at kimmel dot us>
rdk at kimmel.us
Tue Oct 15 19:37:37 CEST 2013
I have observed that when I reimplement QGraphicsView::contextMenuEvent and have also reimplemented QGraphicsItem::contextMenuEvent, that the graphics view seem to block access to the individual context menus of the item(s). My workaround is as follows:
void MyGraphicsView::contextMenuEvent(QContextMenuEvent *event)
{
QPointF p=event->pos();
QGraphicsItem* item=itemAt(p.x(),p.y());
if (item != NULL) {
MyGraphicsItem* item2=dynamic_cast<MyGraphicsItem*>(item);
if (item2) {
QGraphicsView::contextMenuEvent(event);
return;
}
}
QMenu menu();
menu.addAction("Action1");
menu.addAction("Action2");
menu.exec(event->globalPos());
}
This method works, but has the disadvantage of requiring rework for every newly added QGraphicsItem with its own context menu. My question is:
Is there a better/preferred way?
--
rdk
More information about the Interest
mailing list