有了这段代码,我可以在3秒内从0页到1页。如何使它在0,1,2,3,0,1,2,3页的循环中工作?
self.Page.setCurrentIndex(0)
QTimer.singleShot(3000, lambda: self.Page.setCurrentIndex(1))发布于 2022-05-16 17:58:58
您需要接受currentIndex()并添加1,如果结果等于count(),只需将其重置为0。
虽然它可以用lambda来完成,但是它会使它变得繁琐和不容易读,所以函数是首选的选择。
self.timer = QTimer()
self.timer.setInterval(3000)
self.timer.timeout.connect(self.switchPage)
self timer.start()
def switchPage(self):
index = self.Page.currentIndex() + 1
if index == self.Page.count():
index = 0
self.Page.setCurrentIndex(index)https://stackoverflow.com/questions/72260436
复制相似问题