如何在 QMessageBox 中集成动画 GIF?
How do I integrate an animated GIF in a QMessageBox?
我想要一个 QMessageBox
以移动的 GIF 作为图标。所以我做了这个:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import os
import sys
def msg_wait(s):
msg = QMessageBox()
msg.setIconPixmap(QPixmap('wait.gif').scaledToWidth(100))
msg.setText(s)
msg.setWindowTitle(" ")
msg.setModal(False)
# msg.setStandardButtons(QMessageBox.Ok)
msg.show()
return msg
class SurfViewer(QMainWindow):
def __init__(self, parent=None):
super(SurfViewer, self).__init__()
self.parent = parent
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)
self.msg=msg_wait('blablabla')
self.msg.setStandardButtons(QMessageBox.Cancel)
def main():
app = QApplication(sys.argv)
ex = SurfViewer(app)
ex.setWindowTitle('NMM Stimulator')
ex.showMaximized()
ex.show()
# ex.move(0, 0)
# ex.resizescreen()
sys.exit(app.exec_( ))
if __name__ == '__main__':
main()
GIF 在哪里:
但结果是固定图像。
我怎样才能使它动画化?
我用 QMovie
class 尝试了一些东西,但我无法在 QMessageBox.setIconPixmap
函数
中设置它
必须使用 QMovie
,但是为此首先要直接访问 QLabel
,使用 findChild
:
def msg_wait(s):
msg = QMessageBox()
# create Label
msg.setIconPixmap(QPixmap('wait.gif').scaledToWidth(100))
icon_label = msg.findChild(QLabel, "qt_msgboxex_icon_label")
movie = QMovie('wait.gif')
# avoid garbage collector
setattr(msg, 'icon_label', movie)
icon_label.setMovie(movie)
movie.start()
msg.setText(s)
msg.setWindowTitle(" ")
msg.setModal(False)
# msg.setStandardButtons(QMessageBox.Ok)
msg.show()
return msg
我想要一个 QMessageBox
以移动的 GIF 作为图标。所以我做了这个:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import os
import sys
def msg_wait(s):
msg = QMessageBox()
msg.setIconPixmap(QPixmap('wait.gif').scaledToWidth(100))
msg.setText(s)
msg.setWindowTitle(" ")
msg.setModal(False)
# msg.setStandardButtons(QMessageBox.Ok)
msg.show()
return msg
class SurfViewer(QMainWindow):
def __init__(self, parent=None):
super(SurfViewer, self).__init__()
self.parent = parent
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)
self.msg=msg_wait('blablabla')
self.msg.setStandardButtons(QMessageBox.Cancel)
def main():
app = QApplication(sys.argv)
ex = SurfViewer(app)
ex.setWindowTitle('NMM Stimulator')
ex.showMaximized()
ex.show()
# ex.move(0, 0)
# ex.resizescreen()
sys.exit(app.exec_( ))
if __name__ == '__main__':
main()
GIF 在哪里:
但结果是固定图像。
我怎样才能使它动画化?
我用 QMovie
class 尝试了一些东西,但我无法在 QMessageBox.setIconPixmap
函数
QMovie
,但是为此首先要直接访问 QLabel
,使用 findChild
:
def msg_wait(s):
msg = QMessageBox()
# create Label
msg.setIconPixmap(QPixmap('wait.gif').scaledToWidth(100))
icon_label = msg.findChild(QLabel, "qt_msgboxex_icon_label")
movie = QMovie('wait.gif')
# avoid garbage collector
setattr(msg, 'icon_label', movie)
icon_label.setMovie(movie)
movie.start()
msg.setText(s)
msg.setWindowTitle(" ")
msg.setModal(False)
# msg.setStandardButtons(QMessageBox.Ok)
msg.show()
return msg