from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QProgressBar, QVBoxLayout
from PySide2.QtCore import QThread, Slot, Signal
import time
class myThread(QThread):
change_value = Signal(int)
def run(self):
ct = 0
while ct < 100:
ct += 1
time.sleep(0.3)
self.change_value.emit(ct)
class MyWidget(QWidget):
def __init__(self):
super(MyWidget, self).__init__()
self.setGeometry( 500, 500, 650, 450)
self.setWindowTitle("My Progress bar")
self.initUI()
self.show()
def initUI(self):
self.pgb = QProgressBar()
self.startButn = QPushButton("Start")
self.startButn.clicked.connect(self.startProgressBar)
vbox = QVBoxLayout()
vbox.addWidget(self.pgb)
vbox.addWidget(self.startButn)
self.setLayout(vbox)
def startProgressBar(self):
self.thread = myThread()
self.thread.change_value.connect(self.setProgressVal)
self.thread.start()
def setProgressVal(self, val):
self.pgb.setValue(val)
if __name__ == "__main__":
app = QApplication([])
widget = MyWidget()
#widget.show()
app.exit(app.exec_())