PyQt5 gif 没有出现

问题描述

这是我的代码(简化版):

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication,QWidget
from PyQt5.QtWidgets import QMainWindow
from PyQt5.uic import loadUi
from PyQt5.QtCore import QTimer,QPropertyAnimation,QRect
import sys
from PyQt5.QtGui import QMovie
from pathlib import Path

class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow,self).__init__()

        loadUi("test.ui",self)

        self.movie = QMovie("GIF.gif")
        self.label.setMovie(self.movie)
        self.movie.start()

if __name__ == "__main__":
    app = QApplication(sys.argv)

    mw = MainWindow()
    mw.show()

    sys.exit(app.exec_())

这是我的 UI 文件(简化版):

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="label">
    <property name="geometry">
     <rect>
      <x>240</x>
      <y>200</y>
      <width>371</width>
      <height>151</height>
     </rect>
    </property>
    <property name="text">
     <string/>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

它应该加载一个 UI 文件显示一个 gif。它成功加载了一个 UI,但只显示 gif 左边的未设置动画的部分,其余部分未显示。如果有人可以帮助我,我将不胜感激。它告诉我我需要添加更多细节,但没有,如果您需要某种信息,请随时问我。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)