Skip to content Skip to sidebar Skip to footer

Qt Widget With Transparent Background

(I'm using PySide, but I think the answer would be the same/similar for any language bindings). I'm trying to take the shaped clock example, located here, and cause the face of t

Solution 1:

Got it!

This is from the original example code (constructor):

    ...
    self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
    ...

Here is the modified (and working per my question) version:

    ...
    self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
    self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
    ...

Removing the self.windowFlags() was the part I was missing. (I'm not exactly sure why I needed to remove this or why it was there to begin with... still much to learn).

Solution 2:

If I remember correctly, you should have set its stylesheet also:

self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.setStyleSheet("background:transparent;")

Hope that helps.

Solution 3:

in the clock example ther is :

voidShapedClock::resizeEvent(QResizeEvent * /* event */){
     int side = qMin(width(), height());
     QRegion maskedRegion(width() / 2 - side / 2, height() / 2 - side / 2, side,
                          side, QRegion::Ellipse);
     setMask(maskedRegion);
 }

the "setMask" do the round shape but there's the same in PySide :

defresizeEvent(self, event):
        side = min(self.width(), self.height())
        maskedRegion = QtGui.QRegion(self.width()/2 - side/2, self.height()/2 - side/2, side, side, QtGui.QRegion.Ellipse)
        self.setMask(maskedRegion)

so it should work too ?

Post a Comment for "Qt Widget With Transparent Background"