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

Lost enterEvents / leaveEvents on Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • Some future release
    • 4.4.0, 4.7.1
    • Core: Event loop
    • None

    Description

      When a widget has a custom context menu, once the menu has been shown, then escaped from (no item in the menu select), enterEvents and leaveEvents are no longer triggered for the widget.

      This is most obvious when the widget's window flags is set to Qt::FramelessWindowHint, thought the bug can be reproduced without this.

      Steps to reproduce:

      1 - Run the example application below.
      2 - Move the mouse cursor in and out of the widget. Notice that there is output for every enterEvent and leaveEvent.
      3 - Right-click anywhere within the widget to display the context menu.
      4 - While the menu is displayed, hover over the widget (not the menu) and pres the Esc key to close the menu.
      5 - Again, as in step 2 above, move the mouse cursor in and out of the widget.
      6 - Now notice that there is no longer output for any enterEvent or leaveEvent, indicating that the events are not being triggered.

      The events will return only when an action from the context menu is selected.

      // *****Example Code*****
      #include <QtGui>
      
      class Widget : public QWidget
      {
          Q_OBJECT
      public:
          Widget(QWidget *parent = 0)
              : QWidget(parent), enterCount(0), leaveCount(0)
          {
              setGeometry(500,500,300,300);
              setContextMenuPolicy(Qt::CustomContextMenu);
              connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
      
              menu = new QMenu(this);
              menu->addAction("Dummy");
      
              setWindowFlags(Qt::FramelessWindowHint);
          }
      
      protected:
          void enterEvent(QEvent *event)
          {
              ++enterCount;
              qDebug() << "enterEvent" << enterCount;
              QWidget::enterEvent(event);
          }
      
          void leaveEvent(QEvent *event)
          {
              ++leaveCount;
              qDebug() << "leaveEvent" << leaveCount;
              QWidget::leaveEvent(event);
          }
      
      private slots:
          void showContextMenu(const QPoint &pos)
          {
              menu->exec(mapToGlobal(pos));
          }
      
      private:
          QMenu *menu;
          int enterCount;
          int leaveCount;
      };
      
      #include "main.moc"
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          Widget w;
          w.show();
          return app.exec();
      }
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            gpf Shane McLaughlin
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes