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

Qt::Tool and Qt::WA_TransparentForMouseEvents conflicts and behaves inconsistently on different OSes

    XMLWordPrintable

Details

    • macOS, Windows

    Description

      Reproducer attached. There is a root QWidget with a child QWidget within. That child QWidget has it enter and leave events overridden. On entry, it's going to show another QWidget. And on leaving, it's going to hide that QWidget.

      The setup is simple, but the problem lies in the window flag and attribute specified, i.e.:

              topWidget->setWindowFlags(Qt::Tool);
              topWidget->setAttribute(Qt::WA_TransparentForMouseEvents, true);
              // topWidget->setWindowFlags(Qt::Tool);
      

      in line 14~16. Namely, the "popped up" QWidget is a tooltip and it ignores mouse event. The problem is:

      On Windows:
      If Qt::Tool is set first (how it is written in the first place), then moving mouse cursor inside red QWidget will cause enter/leaveEnter to be registered repeatedly. The other way around (comment out line 14 and uncomment 16) is fine. Moreover, if either Qt::Tool or Qt::WA_TransparentForMouseEvents is used alone (either comment out setAttribute or both setWindowFlags), you'd see the same "events being spammed" problem.

      On macOS:
      If Qt::Tool is set first, then everything is fine. The other way around, then moving mouse cursor inside red QWidget will cause enter/leaveEnter to be registered repeatedly. It is the opposite of Windows behavior. Moreover, if you use Qt::WA_TransparentForMouseEvents alone (comment out both setWindowFlags), you'd see the same "events being spammed" problem. Using Qt::Tool alone is fine. So it is another inconsistency, comparing to Windows behavior.

      Update: a one-line solution for macOS only: use Qt::Popup instead of Qt::Tool. For Windows, strangely it only works when

      setWindowFlags(Qt::FramelessWindowHint | Qt::Popup | Qt::NoDropShadowWindowHint);
      

      is executed first.

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              luqiaochen Luqiao Chen
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes