Qt::WA_TransparentForMouseEvents
Our desktop app has an overlay over the main window with an "aperture" that is made transparent to mouse events by setting the Qt::WA_TransparentForMouseEvents attribute. This used to work well in an earlier version based on Qt 5.9.8.
We have migrated to Qt 6.2.3, and the event pass-through has stopped working on Linux (ubuntu 20.04) and MacOS, but continues to work on Windows.
I assume the attribute is ultimately handled by the window manager. Is this assumption correct?
Could the propagation of the attribute to the window manager possibly have changed between Qt 5.9.8 and Qt 6.2.3?
How can I even test this hypothesis? So far I can only confirm that mouse clicks are not consumed by the "underneath" widget as they should be (and are on Windows).
Are there other ways to achieve z-order event transparency for a widget?
Re: Qt::WA_TransparentForMouseEvents
Quote:
Are there other ways to achieve z-order event transparency for a widget?
As a workaround, you might be able to install an event handler on the overlay that relays the mouse events to the underlying widget. You'll probably need to do some coordinate mapping if the overlay is not exactly the same size and in the same position.
Re: Qt::WA_TransparentForMouseEvents
Quote:
Originally Posted by
d_stranz
As a workaround, you might be able to install an event handler on the overlay that relays the mouse events to the underlying widget. You'll probably need to do some coordinate mapping if the overlay is not exactly the same size and in the same position.
I should have noted that the overlay inherits QDialog. It basically has a 3x3 grid layout, the center of which is the aperture. The aperture gets moved around quite a bit, so the widget underneath varies. In order to identify it I'd probably have to use QApplication::widgetAt(const QPoint&) - which in turn uses Qt::WA_TransparentForMouseEvents.
tl;dr Not sure this leads anywhere, unfortunately.
Added after 12 minutes:
(This super smart forum combines successive posts of mine. How can I keep them separate?)
Things just got a lot stranger...
I played around on Windows which I thought works. Now, I found mouse clicks are passed through overlay/aperture even if I explicitly set
Code:
_aperture->setAttribute(Qt::WA_TransparentForMouseEvents, false);
How can this even be? :confused:
I looked around and found
Code:
_overlay->setWindowFlag(Qt::Tool);
but this line of code makes no difference either and I can just as well comment it out - the mouse clicks are still propagated.
Re: Qt::WA_TransparentForMouseEvents
Let me resolve it myself:
There are 3 tiers of widgets: aperture -> overlay -> main window
aperture was set to Qt::WA_TransparentForMouseEvents
overlay was set to Qt::WA_TranslucentBackground
Now overlay not being explicitly transparent for mouse events explains why the events didn't reach the main window. To set WA_TransparentForMouseEvents explicitly for overlay fixes the issue.
However, WA_TranslucentBackground on Windows appears to implicitly set it transparent for mouse events, too! Thus it accidentally worked in Windows. And as development predominantly takes place on Windows, it went unnoticed on Linux and Mac.
I don't think it has anything to do with the Qt version anymore.
Rather I think it's a Windows bug.