I'm trying to show QProgressBar updates smoothly. The below code is filling up the progress bar from 0 to 100 triggered from a QThread, but I want to show the incremental progress update smoothly. Is there any way to do this?
import time
from PySide2.QtWidgets import QProgressBar, QApplication
from PySide2.QtCore import Slot, QThread, Signal, QObject
class ProgressBarUpdater(QThread):
progressBarValue = Signal(int)
def run(self):
value: int = 0
while value <= 100:
time.sleep(0.1)
self.progressBarValue.emit(value)
value += 5
def main():
app = QApplication([])
pbar = QProgressBar()
pbar.setMinimum(0)
pbar.setMaximum(100)
pbar.show()
@Slot(int)
def progressbar_update(value: int):
pbar.setValue(value)
progressBarUpdater = ProgressBarUpdater()
progressBarUpdater.progressBarValue.connect(progressbar_update)
progressBarUpdater.start()
app.exec_()
if __name__ == "__main__":
main()