Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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
    {
    public:
        explicit MyDialog(QWidget* parent = nullptr) : QDialog(parent)
        {
            setMinimumSize(300, 300);
        }
    
        virtual ~MyDialog()
        {
        }
    
    protected:
        virtual void mousePressEvent(QMouseEvent* event) override
        {
            QDialog::mousePressEvent(event);
    
            if (event->button() == Qt::RightButton)
            {
                QMenu menu;
                menu.addAction("Action 1");
                menu.addAction("Action 2");
                menu.addAction("Action 3");
    
                menu.exec(QCursor::pos());
            }
        }
    };
    
    ///////////////////////////////////////////////////////////////////////////
    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);
        dlg->hide();
    
        connect(btn, &QPushButton::clicked, dlg, &MyDialog::exec);
    }
    
    Widget::~Widget()
    {
    }
    

    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

    Hi,

    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