Qt widget shape from image
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
You would use a combination of QWidget::setMask()
and one of the functions that create QBitmap
masks from QPixmap
s:
- createHeuristicMask()
- createMaskFromColor()
- mask() (should probably be called
createMaskFromAlpha()
instead).
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
).
精彩评论