PyQt QMovie不会循环GIF

时间:2015-07-08 22:46:47

标签: python qt pyqt4

我有一个播放 gif 的工作示例,但它并没有循环GIF。即使我改变了 movie.setCacheMode(QMovie.CacheAll)

任何想法? enter image description here - >动画Gif

from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import *

import sys

class ImagePlayer(QWidget):
    def __init__(self, filename, title, parent=None):
        QWidget.__init__(self, parent)

        # Load the file into a QMovie
        self.movie = QMovie(filename, QByteArray(), self)

        size = self.movie.scaledSize()
        self.setGeometry(200, 200, size.width(), size.height())
        self.setWindowTitle(title)

        self.movie_screen = QLabel()
        # Make label fit the gif
        self.movie_screen.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.movie_screen.setAlignment(Qt.AlignCenter)

        # Create the layout
        main_layout = QVBoxLayout()
        main_layout.addWidget(self.movie_screen)

        self.setLayout(main_layout)

        # Add the QMovie object to the label
        self.movie.setCacheMode(QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.movie_screen.setMovie(self.movie)
        self.movie.start()
        self.movie.loopCount()


if __name__ == "__main__":
    gif = "dotGreen.gif"
    app = QApplication(sys.argv)
    player = ImagePlayer(gif, "was")
    player.show()
    sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:2)

实际上 gif 之前已使用循环选项播放保存。因此将其更改为" 永远"做了伎俩。

Photoshop Gif export with Forever Option