generally speaking ,QProgressBar  The application will do some delay operation , This will cause the main route card ui,PyQt Threads in can solve this problem perfectly , This example uses python Medium time The module delays , And put the delay operation in the sub thread to execute , realization Qt Of UI Real time refresh .
import sys import time from PyQt5.QtCore import QThread, pyqtSignal from
PyQt5.QtWidgets import QWidget, QPushButton, QProgressBar, QVBoxLayout,
QApplication class Thread(QThread): _signal = pyqtSignal(int) # Define the signal type as integer def
__init__(self): super(Thread, self).__init__() def __del__(self): self.wait()
def run(self): for i in range(100): time.sleep(0.1) self._signal.emit(i) # Transmit signal
class Example(QWidget): def __init__(self): super(Example, self).__init__()
self.setWindowTitle('QProgressBar') self.btn = QPushButton(' Start thread ')
self.btn.clicked.connect(self.btnFunc) # Connection slot function self.pbar = QProgressBar(self)
self.pbar.setValue(0) self.resize(300, 300) self.vbox = QVBoxLayout()
self.vbox.addWidget(self.pbar) self.vbox.addWidget(self.btn)
self.setLayout(self.vbox) def btnFunc(self): self.thread = Thread()
# Instantiation thread self.thread._signal.connect(self.signal_accept)
# Connect the signal defined in thread accumulation to the signal receiving function in this class self.thread.start()
# Start thread , The start thread calls the start method , This method calls the run function , So you don't have to call run function self.btn.setEnabled(False)
def signal_accept(self, msg): self.pbar.setValue(int(msg)) # Pass the thread's parameters into the progress bar if
self.pbar.value() == 99: self.pbar.setValue(0) self.btn.setEnabled(True) if
__name__ == "__main__": app = QApplication(sys.argv) ex = Example()
effect : 


©2019-2020 Toolsou All rights reserved,
be based on RK3399 PWM Drive development about Navicat for mysql Of 2003 error Share has surpassed Ningde Era !LG Chemical confirmation to spin off battery business unit 【JAVA】【 Huawei campus recruitment written examination - Software 】2020-09-09Map---Java judge Map Contains a keypython3 Read the file and specify a few lines , And write to another file css Basics 2:flex Multi row layout with gaps Vue el-select obtain label value JQ get request Splicing url parameter ( query criteria )( Essence )2020 year 6 month 26 day C# Class library GUID Help class