RSS Feed

a July 11th, 2008

  1. transparent windows howto

    July 11, 2008 by Oğuz Yarımtepe

    I have been dealing with the qt programming using Python. Till now i mainl created simple GUI working as a on screen display or making simple jobs. I was trying to creade an on screen display. I needed to create transparent window application. After searching and trying here is a simple python code that uses qt4 library that creates a window which includes a transparent png image inside.


    import sys
    from PyQt4 import QtGui, Qt, QtCore

    class Transparent(QtGui.QWidget):

    def __init__(self):
    QtGui.QWidget.__init__(self)
    self.setAttribute(Qt.Qt.WA_NoSystemBackground)
    self.setAutoFillBackground(True)

    pixmap = QtGui.QPixmap("test.png")
    width = pixmap.width()
    height = pixmap.height()

    self.setWindowTitle("Status")
    self.resize(width, height)

    self.label = QtGui.QLabel(self)
    self.label.setPixmap(QtGui.QPixmap("test.png"))

    self.setMask(pixmap.mask())

    def paintEvent(self,event):
    self.setAttribute(Qt.Qt.WA_NoSystemBackground)

    if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    x = Transparent()
    x.show()
    app.exec_()