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

就是对这个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

上一篇:struts2设置非默认路径的struts.properties以及.properties文件解决方案


下一篇:四.Windows I/O模型之重叠IO(overlapped)模型