Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Could not hover on QMenu in a modal dialog
QtWS25 Last Chance

Could not hover on QMenu in a modal dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 366 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sivan
    wrote on last edited by Sivan
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which OS are you running your code on ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sivan
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sivan
          wrote on last edited by
          #4

          Filed a bug in https://bugreports.qt.io/browse/QTBUG-94375

          1 Reply Last reply
          1
          • AndyBriceA Offline
            AndyBriceA Offline
            AndyBrice
            wrote on last edited by
            #5

            For reference, see also:
            https://bugreports.qt.io/browse/QTBUG-88985

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved