如何使用PySide在状态栏中添加进度条?

4

我想在我的应用程序状态栏中添加一个进度条。我找到了这篇文章,但是使用insertWidget()似乎不起作用。

1个回答

11

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

这应该会产生类似于这样的东西:

进度条


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接