Skip to content Skip to sidebar Skip to footer

Animate Using A Pixmap Or Image Sequence In Python With Qt4

I have a small Python script that makes a transparent window for displaying a graphic on screen and I'd like to animate that graphic, but am entirely unsure how or where to even st

Solution 1:

This ended up being a simple correction of an oversight in the end.

imgnumber needed to be outside of the def as self.imgnumber and needed to be named self.imgnumber each time it was changed.

Solution 2:

First, just make sure your animated gif really does have a proper transparent background. The following code works for me, using this fire image as a source:

classTransparent(QtGui.QWidget):

    def__init__(self):
        QtGui.QWidget.__init__(self)
        self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)

        filename = "test.gif"
        
        size = QtGui.QImage(filename).size()

        self.setWindowTitle("Status")

        layout = QtGui.QVBoxLayout(self)
        layout.setMargin(0)

        self.movie = QtGui.QMovie(filename)
        self.label = QtGui.QLabel(self)
        self.label.setMovie(self.movie)

        layout.addWidget(self.label)
        self.resize(size)

        self.movie.start()

This will create a completely transparent and frameless window, with the animated gif playing in a QMovie. There is no black being drawn behind the image. It should fully see through to what ever is underneath.

It is not so far off from your original code. You shouldn't need to set the mask, or do a paint event.

Post a Comment for "Animate Using A Pixmap Or Image Sequence In Python With Qt4"