PyQt5循环图像序列automaticaly

PyQt5循环图像序列automaticaly

问题描述:

我添加代码到我的应用程序打开图像序列与两个按钮prev和next。 我怎么可以设置下一个按钮每秒点击,例如播放序列?PyQt5循环图像序列automaticaly

def nextitem(self): 
    self.listWidget.sortItems() 
    #a = self.choice2.text() 
    count = self.listWidget.count() 
    cur = self.listWidget.currentRow() 
    self.listWidget.setCurrentRow(cur+1) 
    if (cur+1) == count: 
     self.listWidget.setCurrentRow(0) 
    if len(self.choice2.text()) > 0: 
     tex = self.listWidget.currentItem().text() 
     a = self.video_choice_2.setText(tex) 
    self.playVideo2() 

enter image description here

UPDATE 我发现在论坛的功能和它的工作,但我不能停止动画或做别的。

import time 
    repeat_time = 0.3 
    while True: 
     start_time = time.time() 
     self.nextitem() 
     time.sleep(max(repeat_time - (time.time() - start_time), 0.0)) 

您不想使用time.sleep,因为它会锁定进程。改为使用PyQt5.QtCore中的QTimer。 Google有大量的关于如何使用QTimer的例子。

+0

感谢您的信息;我会搜索一下 – seghier

+1

谢谢;我找到一个很好的例子:http://nullege.com/codes/show/[email protected]@[email protected]@[email protected]@[email protected]@bubbleswidget.py/126/PyQt5.QtCore.QTimer – seghier

我找到解决方案,它的工作良好,但当我点击播放按钮两次或多次速度增加,我不能停止动画。

def playSeq(self): 
    self.animation_timer = QTimer(self) 
    self.animation_timer.setSingleShot(False) 
    self.animation_timer.timeout.connect(self.nextitem) 
    self.animation_timer.start(300) 

UPDATE:问题解决 当我点击它总是叫Qtimer之前,但现在它调用start仅

self.animation_timer = QTimer(self) 
    self.animation_timer.setSingleShot(False) 
    self.animation_timer.timeout.connect(self.nextitem) 
def playSeq(self):  
    self.animation_timer.start(300) 
+0

如果你有另外一个问题,请点击[Ask Question](// *.com/questions/ask)按钮。 – ekhumoro

+0

这是同一主题中的另一个问题;为什么我需要再问一次,而不是一个人 - 我确信 - 会像你的评论一样评论:不要问同样的问题,请如果你忍不住不要评论 – seghier

+0

如果你有一个新的问题,请问问通过点击[Ask Question](https://*.com/questions/ask)按钮。如果有助于提供上下文,请包含此问题的链接。 - [来自评论](/ review/low-quality-posts/17560229) –