I have a graphic manager that is used to manage and interact with graphics using mouse input.
Inside the mousePressEvent (not overidden from QWidget, is just a normal method that gets passed mouse location and buttons from a QWidget) I create a QMenu which is displayed on right click and when clicking on a graphic.
if( button == Qt::RightButton && activeGraphic) {
QMenu menu("Edit", view());
QAction * deleteAction = new QAction( "Delete", &menu );
connect( deleteAction, &QAction::triggered, [=](bool) {
_lineGraphicHandler->releaseActiveGraphic();
_lineGraphicHandler->removeGraphic( activeGraphic );
});
menu.addAction( deleteAction );
QAction * settingsAction = new QAction( "Settings", &menu );
connect( settingsAction, &QAction::triggered, [=](bool) {
emit showSettings(QString::fromStdString(activeGraphic->type()));
});
menu.addAction( settingsAction );
connect( &menu, &QMenu::aboutToHide, [=] {
qDebug() << "menu closing";
});
connect( &menu, &QMenu::aboutToShow, [=] {
qDebug() << "menu opening";
});
menu.exec( view()->mapToGlobal( pos.toPoint() ) );
}
This code is used within two different projects and in one project the menu is displayed as expected and in the other project the menu is not visible but able to accept mouse clicks (I originally had a problem with the menu immediately being closed).
The difference between the projects is in the widget hierarchy within which the QMenu resides.
failing project
graphichanlder - QObject
graphicsmode - QObject
graphicwidget - QFrame
graphicsview - QGraphicsView
working project
graphichanlder - QObject
graphicsmode - QObject
videotile - QGraphicsObject
graphicsScene - QGraphicsScene
What am I doing that could be causing this behavior?
Fixed
Discovered this bug https://bugreports.qt-project.org/browse/QTBUG-7556 which explained the problem I was having. Fixed by adding a margin around my QGLWidget so it is no longer fullscreen.