Lucas
Lucas

Reputation: 3119

How to show a popup menu using QGLWidget?

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

Upvotes: 2

Views: 1932

Answers (1)

Vicken Simonian
Vicken Simonian

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

Related Questions