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

时间:2013-07-29 19:08:16

标签: python progress-bar pyside statusbar

我想在应用程序的状态栏中添加进度条。我找到了this post,但使用insertWidget()似乎无效。

1 个答案:

答案 0 :(得分:4)

而不是使用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()

这应该产生这样的东西:

Progress Bar