如何使用PySide将ProgressBar添加到StatusBar?

Jam*_*rtz 4 python statusbar pyside progress-bar

我想将进度条添加到应用程序的状态栏中。我发现了这篇文章,但是使用insertWidget()似乎没有用。

Jam*_*rtz 6

代替使用该insertWidget()方法,而是使用代替addPermanentWidget()

这是一个例子:

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()
Run Code Online (Sandbox Code Playgroud)

这应该产生如下内容:

进度条