Skip to content

One-liner: killing mouse events

Monday, 13 December 2010  |  jaroslaw staniek

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.