开发者

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 QPixmaps:

  • 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜