Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt::WA_TranslucentBackground available everywhere?

Tags:

qt

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.

like image 879
Sebastian Negraszus Avatar asked Oct 27 '11 20:10

Sebastian Negraszus


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.

like image 135
Winand Avatar answered Sep 19 '22 18:09

Winand


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.

like image 39
Luca Carlon Avatar answered Sep 19 '22 18:09

Luca Carlon