2010-04-13 45 views

回答

1

覆蓋QGLWidget類和mouseReleaseEvent(QMouseEvent *事件)函數
然後在mouseReleaseEvent函數中,使用映射的全局位置調用QMenu exec()。

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 
}