I have a custom widget to emulate balloon tips. To be displayed properly, the widget depends on the QWidget attribute Qt::WA_TranslucentBackground
. My application should work on all major platforms (Windows XP, Windows 7, Linux, Mac), so I worry a bit: Is this attribute available on all major platforms? If not, can I query if it is? testAttribute()
doesn't do that. It only returns whether the attribute has been set, not whether setting it has an effect.
For Linux you should check whether compositing is enabled:
bool QX11Info::isCompositingManagerRunning() [static]
e.g.
#ifdef Q_WS_X11
if(QX11Info::isCompositingManagerRunning())
setAttribute(Qt::WA_TranslucentBackground);
#endif
This question is old, but this might help someone.
This should work with the only exception of Linux over X11 when this is configured not to support ARGB. Refer to the QWidget documentation:
Creating Translucent Windows
Since Qt 4.5, it has been possible to create windows with translucent regions on window systems that support compositing.
To enable this feature in a top-level widget, set its Qt::WA_TranslucentBackground attribute with setAttribute() and ensure that its background is painted with non-opaque colors in the regions you want to be partially transparent.
Platform notes:
X11: This feature relies on the use of an X server that supports ARGB visuals and a compositing window manager.
Windows: The widget needs to have the Qt::FramelessWindowHint window flag set for the translucency to work.
Consider reading also the paragraph titled "Transparency and Double Buffering", might be interesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With