Is there a way to show a popup when the user right clicks on an empty portion of the scene?
I'm new at Qt and I've tried slots and subclassing, but to no avail.
No such slot and, respectively:
"error: 'QMouseEvent' has not been declared"
when trying to implement the onMouseRelease
event.
QGraphicsView is the widget used for displaying the contents of the QGraphicsScene. So the correct place to implement the context menu (popup menu) is the QGraphicsView.
You need to reimplement the contextMenuEvent function is your own class inherited from QGraphicsView:
void YourGraphicsView::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
menu.addAction(...);
menu.addAction(...);
...
menu.exec(event->globalPos());
}
See also the Qt's Menus Example.