0

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.

Community
  • 1
  • 1
Will-of-fortune
  • 167
  • 1
  • 3
  • 16
  • 1) It is better to do this on mouse **release** event. 2) Where the `pos` calculated and how? – vahancho Sep 12 '14 at 09:46
  • I have tried it inside mouse release event and the same happens, I agree it makes more sense in release but all the other graphics are the same so for now I'm not breaking our convention. pos is calculated inside a QFrame, I have checked the position is correct by debugging into the QMenu code, but I get different behaviour where the menu is shown and then closed immediately which I put down to the fact I leave the application to go into Visual Studio to debug. – Will-of-fortune Sep 12 '14 at 09:58

0 Answers0