1

How can I create a widget or window that will be just a transparent image? I mean something like in this program: sakura script player
What i tried is:

label = QtGui.QLabel(None,
                    QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
label.setPixmap(QtGui.QPixmap('c:\transparent.png'))
label.setScaledContents(True)

label.show()

but it generates just a rectangle window, in spite of image's transparency

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
chapaev
  • 13
  • 3
  • forgot to mention, im using PyQt4|Python3.2|Windows7, but trying to get some 'crossplatform' code – chapaev May 07 '11 at 11:15
  • OK, solved it! Here's example (plane.png contents alpha-channel): pixmap = QtGui.QPixmap('c:\plane.png') label.setPixmap(pixmap) label.setMask(pixmap.mask()) shitty formatting system – chapaev May 07 '11 at 12:14

1 Answers1

3

You would use a combination of QWidget::setMask() and one of the functions that create QBitmap masks from QPixmaps:

There used to be an xpenguin-like example in the Qt distribution, but they replaced it with a shaped clock (if you have Qt 3.3 around, check out examples/tux/tux.cpp).

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90