Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-94375

Could not hover on QMenu in a modal dialog

    XMLWordPrintable

Details

    • macOS
    • ae3594436b9b0540ef94379a73bf8fec8d3b7465

    Description

      Could not hover on a menu which is executed from a modal dialog.
      Here is the 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()
      {
      }
      

      1) Compile and run the above code

      2) Click on the press button to open the dialog.

      3) On the dialog, right click and try to hover on the actions.

      4) Notice it is not possible to hover

       

      The only workaround that I have found so far is to create the menu in modal dialog with a parent. For example:

      QMenu menu(this);
      

      This issue does not happen on a modeless dialog or widget

      Attachments

        1. QtMenuHover.zip
          5 kB
          sivan nanthiran
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            nanthiran2005 sivan nanthiran
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes