就是对这个contextMenuEvent 事件重新实现,在这个事件函数中创建菜单,大概就是这样。
void MyItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu *menu = new QMenu;
menu->addAction("Action 1");
menu->addAction("Action 2");
menu->popup(event->screenPos()); connect(menu, SIGNAL(triggered(QAction *)),
object, SLOT(triggered(QAction *)));
}
referrences:
http://www.qtcentre.org/threads/5187-Popup-menu-for-a-QGraphicsItem
http://*.com/questions/19868383/how-to-handle-right-mouse-click-event-for-qgraphicsitem