QProgressBar member progress bar, the progress bar is horizontal or vertical. In dealing with a longer time-consuming task, you might use the progress bar component. Because the image using the progress bar can tell the user's current task in progress.
Progress of common functions as follows:
function |
value | content |
setInvertedAppearance |
True/False |
Set to the progress bar. Ture: from left to right or top to bottom False: right to left or from bottom to top The default is True |
setOrientation |
Qt.Horizontal/ Qt.Vertical |
Set the progress bar is horizontal, vertical. The default is level |
setMinimum |
0~99 | Set the minimum, default 0 |
setMinimum |
0~99 | Set the maximum value, the default 99 |
setFormat |
%p % v %m |
Text next to the progress bar display settings: Expressed as a percentage; It represents the current value; Expressed as total steps. The default is the percentage (% p). |
Examples are as follows:
. 1 Import SYS, Time 2 from PyQt5.QtWidgets Import the QApplication, the QWidget, QProgressBar, the QPushButton, QVBoxLayout, . 3 from PyQt5.QtCore Import the Qt . 4 . 5 . 6 class mywin (the QWidget): . 7 DEF the __init__ (Self): . 8 . Super () the __init__ ( ) . 9 self.setWindowTitle ( ' progress bar ' ) 10 self.step = 0 # initial value is set to 0 . 11 self.initUI () 12 is 13 is DEFinitUI (Self): 14 self.pbar = QProgressBar () 15 16 self.pbar.setInvertedAppearance (False) # to the progress bar . 17 self.pbar.setOrientation (Qt.Horizontal) # direction of the progress bar 18 is self.btn the QPushButton = ( ' start ' , Self) . 19 20 is self.v_layout = QVBoxLayout, () 21 is self.v_layout.addWidget (self.pbar) 22 is self.v_layout.addWidget (self.btn) 23 is self.setLayout (self.v_layout) 24 25 Self. btn.clicked.connect (self.action) 26 27 def action(self): 28 self.pbar.setMinimum(0) 29 self.pbar.setMaximum(0) 30 while self.step < 1000: 31 self.pbar.setValue(self.step) 32 self.step += 1 33 time.sleep(0.001) 34 else: 35 self.step = 0 36 print('done') 37 self.pbar.setValue(self.step) 38 39 40 if __name__ == '__main__': 41 app = QApplication(sys.argv) 42 mywin = Mywin() 43 mywin.show() 44 sys.exit(app.exec_())
Display as follows:
Display for the Marquee effect, the text does not show progress. This is because the code was added to the
self.pbar.setMinimum(0) self.pbar.setMaximum(0)
If the above two lines of code removed, displayed normal results, as follows: