Qt编程之对QGraphicsItem点击右键弹出菜单

就是对这个contextMenuEvent 事件重新实现,在这个事件函数中创建菜单,大概就是这样。

 

 

 1 void MyItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
 2 {
 3     QMenu *menu = new QMenu;
 4     menu->addAction("Action 1");
 5     menu->addAction("Action 2");
 6     menu->popup(event->screenPos());
 7  
 8     connect(menu, SIGNAL(triggered(QAction *)),
 9                  object, SLOT(triggered(QAction *)));
10 }
View Code

 

 

referrences:

http://www.qtcentre.org/threads/5187-Popup-menu-for-a-QGraphicsItem

http://stackoverflow.com/questions/19868383/how-to-handle-right-mouse-click-event-for-qgraphicsitem

posted @ 2015-06-01 15:35  foo__hack  阅读(1145)  评论(0编辑  收藏  举报