SoFunction
Updated on 2024-11-15

pyqt5 implement popup progress bar in other window

Requirement: while importing the video, use the caffe trained model to extract the features of the video, this process is more time consuming, so you need a progress bar, otherwise you think the program is dead.

Some of the problems that occur in the strip with progress bars are:

1、Progress bar window can be popped up but no progress bar, label, button, etc.

2. The content of the progress bar window is complete, but the progress of the progress bar is not updated

3, progress bar above problem solved, but in the progress bar window close (), the program appears unresponsive phenomenon.

Question one:

Distinguish between show, exec_difference

Question two:

(100), simulation of 100 documents

Problem 3: Something is wrong with a certain loop while......

Progress Bar dialog box:

 # -*- coding: utf-8 -*-
##set progressbar
 
from  import QApplication,QWidget,QDialog,QLabel,QLineEdit,QProgressBar,\
  QPushButton,QVBoxLayout,QHBoxLayout,QGridLayout,QDialogButtonBox
from  import Qt, QBasicTimer, QThread
import sys
 
class ProgressBar(QDialog):
  def __init__(self, fileIndex,filenum,parent = None):
    super(ProgressBar, self).__init__(parent)
 
    (350,100)
    (("Processing progress"))
 
     = QLabel(("Processing:" + "  " + str(fileIndex) + "/" + str(filenum)))
     = QLabel(("Extract feature:"))
    
     = QProgressBar(self)
    (0)
    (100) # Total processes converted to 100
    (0) # Progress bar initialized to 0
 
    TipLayout = QHBoxLayout()
    ()
 
    FeatLayout = QHBoxLayout()
    ()
    ()
 
    #  = QPushButton('start',self)
     = QPushButton('cancel', self)
    # ()
 
    buttonlayout = QHBoxLayout()
    (1)
    ()
    # (1)
    # ()
 
    layout = QVBoxLayout()
    # layout = QGridLayout()
    (FeatLayout)
    (TipLayout)
    (buttonlayout)
    (layout)
    ()
 
    # ()
 
    ()
    # ()
    #  = QBasicTimer()
    #  = 0
 
  def setValue(self,value):
    (value) 
 
  def onCancel(self,event):
    ()
 
def main():
  app = QApplication()
  fileIndex = '3'  # How many documents are currently being processed
  filenum = '10'  #Total number of documents, displayed in label
  progress = ProgressBar(fileIndex,filenum,0)
  ()
  app.exec_()
 
if __name__ == '__main__':
  main()

The pair dialog box pops up in the program:

 = (,)
for i in range(n*step,(n+1)*step):
    # (0.05)
    (i+1) # Update the value of the progress bar
    (int(*100)) # Simulate file transfer, the progress bar can increase a little bit instead of a lot at once, or not at all
    () #Real-time display
() # Remember to close the progress bar

Above this pyqt5 implementation in other windows pop-up progress bar is all I have shared with you, I hope to give you a reference, and I hope you support me more.