DEC
13
2010

One-liner: killing mouse events

Tomaz shares a hint with us:
Have you ever tried to create an overlay on top of some QWidgets to make them not acessible, but still visible to the user? I’m not saying about setEnabled(false), but to create a semitransparent – mask on top of some widgets with something inside, a modal dialog or so.
[..]
aseigo had already told me that it was possible by using a QGraphicsView...

No need to use a cannon to kill a fly.

Just use this *elegant* call:

myOverlayWidget->setAttribute(Qt::WA_TransparentForMouseEvents);

Other calls like setAutoFillBackground() may be still needed of course but you can use plain widgets.

Comments

So when would this be used?


By sreich at Tue, 12/14/2010 - 23:12

It can be used when all you need is a top-level widget, not separate window, so if you agree that the widget can't be moved outside of the parent window. As a bonus transparency/translucency works in this model without a need for advanced composition manager in your display (eg. in X11). This may be unneeded optimization on modern desktop but for mobile solutions without desktop-like window management it's useful since most often what you use are full-screen apps.


By Jarosław Staniek at Wed, 12/15/2010 - 13:21