我有方法可以向上/向下动画两个全屏窗口,因为动画有点麻烦,我决定将动画作为一个单独的线程运行,我不确定这是否是锯齿状动画的解决方案,但是我想要尝试一下。现在当我试图调用动画的方法时 像这样
try:
t = Thread(None, self.animateUpSlideShow, None)
t.start()
t.join()
except Exception as errtxt:
print errtxt
我收到了以下错误
QObject::startTimer: QTimer can only be used with threads started with QThread
以下是以下方法:
def animateUpSlideShow(self):
""" animate the slideshow window back up to view mode
and starts the slideShowBase where it was paused.
"""
if self._slideShowWin:
self.animateUpGallery()
self.animation = QtCore.QPropertyAnimation(self._slideShowWin, "geometry")
self._slideShowWin.bar.show()
self._slideShowWin.bar.galrBtn.setIcon(QtGui.QIcon(':/images/galryIcon.png'))
self.animation.setDuration(self.__animRate)
self.animation.setStartValue(QtCore.QRect(0, self.__sh,
self.__sw, self.__sh))
self.animation.setEndValue(QtCore.QRect(0, 0, self.__sw, self.__sh))
self.animation.start()
self._slideShowWin.activateWindow()
self._slideShowWin.raise_()
self._slideShowWin.playPause()
那么我应该如何在单独的线程中为窗口设置动画而不会出现上述错误?
更新 我按照互联网上的示例使用QThreads,但当画廊动画向上滑动时,锯齿状动画仍然存在see link for full code:
def _animateUpOpen(self):
""" this method calls the method that animate the windows,
helps in separating toggle button call from keyboard
key press calls
"""
self.workThread = WorkThread()
self.connect( self.workThread, QtCore.SIGNAL("update(QString)"), self.animateUpSlideShow)
self.workThread.start()
# self.animateUpSlideShow()
class WorkThread(QtCore.QThread):
def __init__(self):
QtCore.QThread.__init__(self)
def __del__(self):
self.wait()
def run(self):
for i in range(1):
time.sleep(0.3) # artificial time delay
self.emit( QtCore.SIGNAL('update(QString)'), "from work thread " + str(i) )
self.terminate()
return
请帮助正确实施: - )