Question

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)
Was it helpful?

Solution

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.

OTHER TIPS

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.

Try this for your widgets:

widget.setAutoFillBackground(True)

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top