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
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to