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

QWindow's Enter and Leave events are invoked too many times after manual resizing of a window on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.4.0
    • GUI: Window management
    • None
    • macOS 12.6, macOS 10.15
    • macOS

    Description

      When I am resizing a window by dragging its edges or corners with a mouse so that the mouse cursor actually enters and leaves the window rectangle while dragging, several enter and leave events are emitted once the mouse button is released. This happens only on macOS but not on Windows and X11. Therefore it constitutes interplatform inconsistency and possible performance hit on macOS.

      Consider this simple code:

      #include <QGuiApplication>
      #include <QResizeEvent>
      #include <QWindow>
      
      class Window : public QWindow
      {
      protected:
         void resizeEvent(QResizeEvent *event) override
         {
             qDebug() << event;
             QWindow::resizeEvent(event);
         }
      
         bool event(QEvent *event) override
         {
             if (event->type() == QEvent::Enter || event->type() == QEvent::Leave)
             {
                  qDebug() << event;
             }
             return QWindow::event(event);
         }
      };
      
      int main(int argc, char *argv[])
      {
         QGuiApplication a(argc, argv);
         Window w;
         w.show();
         return a.exec();
      }
      
       

      Steps to reproduce:
      1) Run the code and grip the window by its edge or corner with a mouse button
      2) Start resizing the window by dragging the edge or the corner with the mouse so that the mouse pointer leaves and enters the window area several times (e.g. quickly expand and shrink the window's size multiple times while still keeping mouse button pressed). --> Resize events are logged while you are resizing the window.
      3) When you release the mouse button to stop the resizing, multiple Enter and Leave events are logged. This is IMHO wrong.

      Example of output after resizing and then releasing the button:

      //... many resize events due to resizing for a while
      QResizeEvent(258, 160)
      QResizeEvent(259, 162)
      QResizeEvent(256, 163)
      QResizeEvent(252, 164)
      QResizeEvent(248, 165)
      QResizeEvent(245, 163)
      QResizeEvent(244, 161)
      // here I stopped resizing and released the mouse button
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(293.172,75.1953))
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(316.629,68.6758))
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(246.027,71.7852))
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(257.77,71.2383))
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(276.273,69.2266))
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(296.141,66.2344))
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(316.605,63.2422))
      QEvent(Leave, 0x16eea5e30)
      QEnterEvent(QPointF(303.117,59.2891))
      //... and more enter and leave events follow
      // note that sometimes there are many, sometimes only a few, sometimes none
      

      On Windows and X11 the events are invoked differently. When the mouse gets near the edge or corners of the window (so that normal "arrow" mouse cursor changes to a "resize" cursor), Leave event is invoked. And after resizing is finished, no Leave and Enter events are invoked.

      //... many resize events due to resizing for a while
      QResizeEvent(258, 160)
      QResizeEvent(259, 162)
      QResizeEvent(256, 163)
      QResizeEvent(252, 164)
      QResizeEvent(248, 165)
      QResizeEvent(245, 163)
      QResizeEvent(244, 161)
      // here I stopped resizing and released the mouse button
      // there are no enter and leave events at the end!!!
      

      I would expect that this should behave the same on all platforms. So this should also be the expected outcome on macOS.

      Attachments

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

        Activity

          People

            vestbo Tor Arne Vestbø
            vladimir.kraus Vladimir Kraus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes