title: PyQt progress bar not updating or appearing until 100%
body: <p>EDIT: <em>There are a number of similar posts on PyQt4 progress bars not updating. They all focus on the issue of threads &amp; where the program actually updates the window. Although helpful, my code was so structured that the replies were not practical. The accepted answer given here is simple, to the point &amp; works.</em></p>
  
  <p>I am using Python 2.7 and PyQT 4 on a Win 7 x64 machine.</p>
  
  <p>I am trying to clear my window of one widget, an 'Accept' button, see code, and replace it with a progress bar.</p>
  
  <p>Even though I close the 'Accept' button &amp; add the progress bar before the processing loop is entered into. The window is only updated after the loop has finished &amp; the progress bar jumps straight to 100%.</p>
  
  <p>My code,</p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  import sys
  import time
  
  class CentralWidget(QtGui.QWidget):
  
      def __init__(self, parent=None):
          super(CentralWidget, self).__init__(parent)
  
          # set layouts
          self.layout = QtGui.QVBoxLayout(self)
  
          # Poly names
          self.pNames = QtGui.QLabel("Import file name", self)  
          self.polyNameInput = QtGui.QLineEdit(self) 
  
          # Polytype selection
          self.polyTypeName = QtGui.QLabel("Particle type", self)
          polyType = QtGui.QComboBox(self)
          polyType.addItem("")
          polyType.addItem("Random polyhedra")
          polyType.addItem("Spheres")
          polyType.addItem("Waterman polyhedra")
          polyType.activated[str].connect(self.onActivated)
  
          # Place widgets in layout        
          self.layout.addWidget(self.pNames)
          self.layout.addWidget(self.polyNameInput)
          self.layout.addWidget(self.polyTypeName)
          self.layout.addWidget(polyType)
          self.layout.addStretch()
  
      # Combobox choice
      def onActivated(self, text):
  
          if text=="Random polyhedra":
              self.randomPolyhedra(text)     
          if text=="Spheres":         # not implementaed yet
              self.polyTypeName.setText("Not implemented yet.")
              self.polyTypeName.adjustSize()      
          if text=="Waterman polyhedra": # not implementaed yet
              self.polyTypeName.setText("Not implemented yet.")
              self.polyTypeName.adjustSize()   
  
      # New options for random polyhedra choice    
      def randomPolyhedra(self, text):    
  
          self.polyNumberLbl = QtGui.QLabel("How many: ", self)            
          self.polyNumber = QtGui.QLineEdit(self) 
          self.acceptSeed = QtGui.QPushButton('Accept') # Accept button created
          self.acceptSeed.clicked.connect(lambda: self.ranPolyGen())
          self.layout.addWidget(self.polyNumberLbl)
          self.layout.addWidget(self.polyNumber)
          self.layout.addWidget(self.acceptSeed)      # Accept button in layout
          self.randFlag = True
          self.polyTypeName.setText(text)
          self.polyTypeName.adjustSize()
  
      # Act on option choices for random polyhedra 
      def ranPolyGen(self):
  
          polyCount = int(self.polyNumber.text())
          self.progressBar = QtGui.QProgressBar() # Progress bar created
          self.progressBar.setMinimum(1)
          self.progressBar.setMaximum(polyCount)
          self.acceptSeed.close()                 # Accept button closed
          self.layout.addWidget(self.progressBar) # Add progressbar to layout
          for poly in range(1, polyCount+1):
              time.sleep(1) # Calls to main polyhedral generating code go here
              print poly
              self.progressBar.setValue(poly)
          self.doneLbl = QtGui.QLabel("Done", self)
          self.layout.addWidget(self.doneLbl)
  
  # Creates GUI
  class Polyhedra(QtGui.QMainWindow):
  
      def __init__(self):
  
          super(Polyhedra, self).__init__()
  
          # Place central widget in layout
          self.central_widget = CentralWidget(self)
          self.setCentralWidget(self.central_widget)
  
          # Set up window        
          self.setGeometry(500, 500, 300, 300)
          self.setWindowTitle('Pyticle')
          self.show()
  
      # Combo box
      def onActivated(self, text):
  
          self.central_widget.onActivated(text)
  
  
  def main():
  
      app = QtGui.QApplication(sys.argv)
      poly = Polyhedra()
      sys.exit(app.exec_())
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>Below is a picture of during loop execution &amp; after completion.</p>
  
  <p>I dont think I have got my head around the addWidget() method. I was under the impression that this would add another widget to the present layout (a vbox layout here) &amp; that the .close() method removed a widget when directed to do so.</p>
  
  <p>What am I missing?</p>
  
  <p><img src="https://i.stack.imgur.com/AoIcB.png" alt="During loop execution &amp; after."></p>