Reputation: 3119
how to show a context menu when you right click within a QGLWidget?
Upvotes: 2
Views: 1932
Reputation: 411
Override the QGLWidget class and the mouseReleaseEvent( QMouseEvent * event ) function
Then in the mouseReleaseEvent function, call QMenu exec() with the mapped global position.
void MyWidget::mouseReleaseEvent ( QMouseEvent * event )
{
if(event->button() == Qt::RightButton)
{
QMenu menu;
QAction* openAct = new QAction("Open...", this);
menu.addAction(openAct);
menu.addSeparator();
menu.exec(mapToGlobal(event->pos()));
}
QGLWidget::mouseReleaseEvent(event); //Dont forget to pass on the event to parent
}
Upvotes: 1