views:

1860

answers:

3

Hello, I try to make the background of my window transparent. But under widgets which are on it i see parts of my desktop-image. Now i have this in constructor:

    self.setFocusPolicy(Qt.StrongFocus)
    self.setAttribute(Qt.WA_QuitOnClose,True)

    self.setBackgroundRole(QtGui.QPalette.Base)
    self.setAttribute(Qt.WA_NoSystemBackground)
+2  A: 

Try this for your widgets:

widget.setAutoFillBackground(True)

I think you could also set it in the Qt Designer.

Georg
It doesn't help =(
Ockonal
I've also tried to draw transparent png-image... It doesn't work too =(.
Ockonal
It would work if you were doing anything else other than a transparent background on your main window and opaque on your child widget.
Chris Cameron
+4  A: 

I've just found this:

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.

PyQt is still Qt 4.4, maybe that is the problem.

Georg
There isn't Qt::WA_TranslucentBackground attribute in PyQt =(. Any ideas?
Ockonal
+1: That is what gs is saying. You can't do it because PyQt was created against Qt 4.4, and so the semi-transparent features you're looking for aren't available yet.
Chris Cameron
+2  A: 

Further to gs's answer, this faq explains why (before Qt 4.5) you cannot achieve this:

FAQ Link:

There is no direct support for partial transparency, where the window is transparent and the widgets on it are not in Qt.

Remember, PyQt's most recent version was created against Qt 4.4, and so does not support the semi-transparent window you desire. gs's other answer, about setAutoFillBackground(True) would work if you were setting the background colour of your main window to anything other than transparent.

Also, see the documentation for Qt.WA_NoSystemBackground, it says you can't depend on the transparent effect that you have so far had:

Qt::WA_NoSystemBackground

Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. Note: Unlike WA_OpaquePaintEvent, newly exposed areas are never filled with the background (e.g after showing a window for the first time the user can see "through" it until the application processes the paint events). This is set/cleared by the widget's author.

Chris Cameron