views:

136

answers:

1

Hi, how to show a context menu when you right click within a QGLWidget?

+1  A: 

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()));
    }
}
Vicken Simonian