Search code examples
qtqt4contextmenuqgraphicsview

How to show pop menu on QGraphicsView?


How to show a pop up menu in Qt while right clicking the QGraphicsView? Please help


Solution

  • QGraphicsView is derived from QWidget, so just reimplement contextMenuEvent(QContextMenuEvent* event) to spawn a QMenu. If you want one to appear when right-clicking on QGraphicsItems in the view, then you will have to reimplement contextMenuEvent(QGraphicsSceneContextMenuEvent* event) in the items.