Search code examples
pythonprogress-barpysidestatusbar

How do I add a ProgressBar to the StatusBar using PySide?


I'm wanting to add a progress bar into my application's status bar. I've found this post, however using insertWidget() doesn't appear to be working.


Solution

  • Instead of using the insertWidget() method use instead addPermanentWidget().

    Here's an example:

    class SampleBar(gui.QMainWindow):
        """Main Application"""
    
    
        def __init__(self, parent = None):
            print('Starting the main Application')
            super(SampleBar, self).__init__()
            self.initUI()
    
        def initUI(self):
            # Pre Params:
            self.setMinimumSize(800, 600)
    
            # File Menus & Status Bar:
            self.statusBar().showMessage('Ready')
            self.progressBar = gui.QProgressBar()
    
    
            self.statusBar().addPermanentWidget(self.progressBar)
    
            # This is simply to show the bar
            self.progressBar.setGeometry(30, 40, 200, 25)
            self.progressBar.setValue(50)
    
    def main():
        app = gui.QApplication(sys.argv)
        main = SampleBar()
        sys.exit(app.exec_())
    
    if __name__ == '__main__':
        main()
    

    This should produce something like this:

    Progress Bar