1
我有一个图像序列呈现出来。我想在一个简单的QMainWindow或QDialog中进行回报。这是我的目标。它将图像加载到qlabel中,但我无法看到正在更新的标签,它只显示上次加载的图像,而没有任何介于两者之间的图像。 也许有人知道什么?使用Qt播放图像序列QMainWindow
from PySide import QtCore, QtGui
import shiboken
import maya.OpenMayaUI as apiUI
import time
def getMayaWindow():
"""
Get the main Maya window as a QtGui.QMainWindow instance
@return: QtGui.QMainWindow instance of the top level Maya windows
"""
ptr = apiUI.MQtUtil.mainWindow()
if ptr is not None:
return shiboken.wrapInstance(long(ptr), QtGui.QWidget)
class Viewer(QtGui.QMainWindow):
def __init__(self, parent = getMayaWindow()):
super(Viewer, self).__init__(parent)
self.setGeometry(400, 600, 400, 300)
self.setUi()
def setUi(self):
self.label = QtGui.QLabel()
self.setCentralWidget(self.label)
def showUi(self):
self.show()
def loadImage(self, path):
self.label.clear()
image = QtGui.QImage(path)
pp = QtGui.QPixmap.fromImage(image)
self.label.setPixmap(pp.scaled(
self.label.size(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
x = Viewer()
x.showUi()
for i in range(1, 11):
x.loadImage("C://anim%03d.png" % i)
time.sleep(0.5)
不熟悉python,但我的C++眼睛告诉我,你在循环中改变pixmaps,并睡眠所有的GUI线程。这是不正确的。尝试使用QTimer用于此目的,信号超时,创建插槽并更改此插槽中的像素映射。如果我不对,或者这对你有帮助,指出我。 – Chernobyl 2014-11-05 20:49:32
它阻止了GUI。我只是尝试qLabel.repaint(),现在播放该序列。但仍然阻止了GUI。 我会尝试QTimer,看看它是否仍然阻止UI – arvidurs 2014-11-05 20:59:18
没有QTimer不会阻止GUI,我发布这个答案,因为它是一个解决方案,我也添加了解释为什么它不会阻止GUI线程。 – Chernobyl 2014-11-05 21:03:33