This question has already been answered:
I want the calculation process in my python program to display the QProgressBar. Wrote a class:
class ProgressBar(QWidget): def __init__(self): super().__init__() self.pbar = QProgressBar(self) self.init_ui() def init_ui(self): self.pbar.setGeometry(30, 40, 200, 25) self.pbar.setValue(0) self.setGeometry(400, 300, 280, 170) self.setWindowTitle('Updating...') self.show() def loading(self, percentage): self.pbar.setValue(percentage)
The instance is created in another class, and the current number of percents was supposed to be passed through the loading function. The simplest example:
pb = ProgressBar() for i in range(100): pb.loading(i) time.sleep(1)
As a result, the ProgressBar is created, but displayed as an empty widget until 100% comes, then it closes.
Apparently, somewhere you need to specify the correct signal, tried several options to set the slot and the signal through valueChanged () did not work. Tell me how to fix it?
QApplication.processEvents()
in a loop, afterpb.loading(i)
- Pavel Gridin