Results 1 to 4 of 4

Thread: Qt::WA_TransparentForMouseEvents

  1. #1
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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?
    Last edited by zaphod.b; 23rd May 2022 at 15:11.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt::WA_TransparentForMouseEvents

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt::WA_TransparentForMouseEvents

    Quote Originally Posted by d_stranz View Post
    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
    Qt Code:
    1. _aperture->setAttribute(Qt::WA_TransparentForMouseEvents, false);
    To copy to clipboard, switch view to plain text mode 
    How can this even be?

    I looked around and found
    Qt Code:
    1. _overlay->setWindowFlag(Qt::Tool);
    To copy to clipboard, switch view to plain text mode 
    but this line of code makes no difference either and I can just as well comment it out - the mouse clicks are still propagated.
    Last edited by zaphod.b; 23rd May 2022 at 17:27.

  4. #4
    Join Date
    Jun 2006
    Posts
    81
    Thanks
    6
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  5. The following user says thank you to zaphod.b for this useful post:

    d_stranz (25th May 2022)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.