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.

- 11,915
- 7
- 43
- 70
2 Answers
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.

- 2,093
- 3
- 28
- 48
-
2And, for anyone who wanders in off Google, if you find yourself needing to support non-composited desktops for something like a rounded OSD or a speech balloon popup, the Qt [ShapedClock](https://doc.qt.io/qt-5/qtwidgets-widgets-shapedclock-example.html) example demonstrates how to use `setMask` to produce a non-square window without compositing. – ssokolow Sep 13 '16 at 11:17
-
Note that sometimes to get `Qt::WA_TranslucentBackground` to work in linux without `setMask`, you also have to enable a few more attributes and a window flag. https://stackoverflow.com/a/30596357/999943 – phyatt Sep 14 '17 at 15:10
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.

- 9,546
- 13
- 59
- 91
-
How common or rare is it for a contemporary Linux to not support ARGB? Can I somehow query it? – Sebastian Negraszus Oct 27 '11 at 22:27
-
I don't think you will have problems with that with recent hardware/distributions. Anyway you should get information by using xdpyinfo or looking at the configuration file xorg.conf. You might have some problems with embedded linux systems maybe. This gives something more: http://stackoverflow.com/questions/2434511/what-pixel-format-does-x-server-use. – Luca Carlon Oct 27 '11 at 23:24