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

Enter event not delivered after showing & closing (context) Menu by click on outside

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.6.1
    • 5.6.1
    • QPA: X11/XCB
    • None
    • 5.6 branch as of commit c7e2133, debian unstable, xcb
    • c511466d747d99ee76465cfe90ce594fa1f27469

    Description

      If the menu is closed by a click on outside of menu and the app window itself, then the Enter event is not delived upon hovering the mouse over the app window, e.g.:

      ...
      event Enter
      event WindowActivate
      event ActivationChange
      event MouseButtonPress
      event ContextMenu
      event ChildAdded
      event ChildPolished
      event Leave
      clicking outside of menu and app itself
      event ChildRemoved
      moving mouse over app window
      event ToolTip
      event MouseButtonPress
      event ContextMenu
      event ChildAdded
      event ChildPolished
      clicking outside of menu and app itself
      event ChildRemoved
      moving mouse over app window
      event ToolTip
      moving mouse out of app window
      event Leave
      event WindowDeactivate
      event ActivationChange

      Example:

      leavewidget.h
      #if !defined(LEAVEWIDGET_H)
      #define LEAVEWIDGET_H
      
      #include <QFrame>
      
      class LeaveWidget : public QFrame
      {
          Q_OBJECT
      public:
          LeaveWidget(QFrame * parent = 0, Qt::WindowFlags f = 0);
      
      protected:
          virtual bool event(QEvent * event) override;
          virtual void contextMenuEvent(QContextMenuEvent *event) override;
      
      private:
          void showMenu();
      };
      
      #endif //LEAVEWIDGET_H
      
      leavevidget.cpp
      #include "leavewidget.h"
      #include <QDebug>
      #include <QMouseEvent>
      #include <QMetaEnum>
      #include <QMenu>
      
      LeaveWidget::LeaveWidget(QFrame * parent, Qt::WindowFlags f)
          : QFrame(parent, f)
      {
          setFixedSize({200, 200});
      }
      
      bool LeaveWidget::event(QEvent * event)
      {
      qDebug() << __FUNCTION__ << QEvent::staticMetaObject.enumerator(QEvent::staticMetaObject.indexOfEnumerator("Type")).valueToKey(event->type());
          if (QEvent::MouseButtonPress == event->type() && Qt::LeftButton == dynamic_cast<QMouseEvent *>(event)->button())
                  showMenu();
          return QFrame::event(event);
      }
      
      void LeaveWidget::contextMenuEvent(QContextMenuEvent *event)
      {
          showMenu();
          QFrame::contextMenuEvent(event);
      }
      
      void LeaveWidget::showMenu()
      {
          QMenu * menu = new QMenu{this};
          menu->setAttribute(Qt::WA_DeleteOnClose);
          menu->addAction(QStringLiteral("test1"));
          menu->addAction(QStringLiteral("test2"));
          menu->popup(QCursor::pos());
      }
      
      main.cpp
      #include "leavewidget.h"
      #include <QApplication> 
      
      int main(int argc, char * argv[])
      {   
          QApplication app{argc, argv};
          LeaveWidget w;
          w.show();
      
          return app.exec();
      }
      

      ref QTBUG-49222

      Attachments

        For Gerrit Dashboard: QTBUG-51573
        # Subject Branch Project Status CR V

        Activity

          People

            zaps166 Błażej Szczygieł
            palinek Palo Kisa
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes