I have created an AutoScroller inside my Gallery but there seems to be a bug that keeps accelerating the speed of scrolling which makes the speed spinbox so unaccurate.
My Idea of autoscrolling is using the QTimer
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Main(object):
def setupUI(self, Project):
Project = QWidget()
Assigned from the outer scope and referenced
Project.setFixedSize(QSize(900, 400))
self.mainScroll = QScrollArea(Project)
self.mainScroll.setGeometry(QRect(80, 0, 740, 400))
self.mainScrollWidget = QWidget()
self.layout = QVBoxLayout(self.mainScrollWidget)
self.layout.addStretch()
self.layout.setGeometry(
QRect(0, 0, self.mainScroll.width(), self.mainScroll.height()))
self.mainScroll.setWidget(self.mainScrollWidget)
self.checkBox = QCheckBox("Auto-Scroll", Project)
self.checkBox.setGeometry(QRect(0, 0, 80, 30))
self.checkBox.toggled.connect(lambda: self.StartTimer(Project))
self.PX_PER_TIME = 1
self.Speed = 10
for i in range(200):
MainWidget = QWidget()
label = QLabel("LABEL NO_%s" % str(i), MainWidget)
label.adjustSize()
self.layout.setSizeConstraint(QLayout.SetFixedSize)
self.layout.addStretch(1)
self.layout.addWidget(MainWidget)
def ScrollDown(self):
vScrollBar = self.mainScroll.verticalScrollBar()
vScrollBar.setValue(vScrollBar.value() + self.PX_PER_TIME)
def StartTimer(self, Project):
if self.checkBox.isChecked():
self.timeleft = self.Speed
qTimer = QTimer(Project)
qTimer.timeout.connect(self.TimerTimout)
qTimer.start(1)
self.ScrollDown()
else:
if type(qTimer) != None:
qTimer.stop()
self.timeleft = self.Speed
def TimerTimout(self):
if self.timeleft > 0:
self.timeleft -= 1
if self.timeleft == 0:
self.timeleft = self.Speed
self.ScrollDown()
Edit
This should reproduce my problem and it kinda explains the type of solution, What I am trying to accomplish is completely stopping the QTimer once the QCheckBox is disabled and reassign all variables to their base state and stop the scrollbar from scrolling.