Nominate our 2022 Qt Champions!

Could not hover on QMenu in a modal dialog

  • Hi all,

    I have just recently upgraded to Qt-5.15.2 from Qt-5.4.1 and noticed that I could not hover on a menu which is executed from a modal dialog.
    Here is my example code:

    class MyDialog : public QDialog
        explicit MyDialog(QWidget* parent = nullptr) : QDialog(parent)
            setMinimumSize(300, 300);
        virtual ~MyDialog()
        virtual void mousePressEvent(QMouseEvent* event) override
            if (event->button() == Qt::RightButton)
                QMenu menu;
                menu.addAction("Action 1");
                menu.addAction("Action 2");
                menu.addAction("Action 3");
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        setMinimumSize(500, 500);
        QPushButton* btn = new QPushButton("Press", this);
        btn->setGeometry(0, 0, 60, 30);
        MyDialog* dlg = new MyDialog(this);
        connect(btn, &QPushButton::clicked, dlg, &MyDialog::exec);

    The above issue only happens when the menu is launched on a modal dialog. It does not happen on a modeless widget/dialog. The current workaround for this issue that I have found so far is to create the menu with a parent. For example,

    QMenu menu(this);

    So I would like to understand if this is a Qt bug or am I missing anything. It worked in Qt-5.4.1.
    Thanks in advance for the advice / help.

  • Lifetime Qt Champion


    Which OS are you running your code on ?

  • Sorry forgot to mention that. I am running on MacOS Catalina 10.15.7

Log in to reply