无法将进度条展开到状态栏的全宽

时间:2014-12-15 03:21:07

标签: qt pyqt qt5 pyside

我希望进度条扩展到状态栏的整个宽度,但为什么那里存在差距? PS。我可以在进度条上添加一些文字,没有像setText()这样的函数,我该怎么做?

那里有小部件或其他东西吗?

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.resize(800, 600)

#        self.lb=QLabel('finding resource   ')

        self.pb = QProgressBar()
        self.pb.setRange(0, 0)
#        self.pb.setTextVisible(False)

#        self.statusBar().addPermanentWidget(self.lb)
        self.statusBar().setSizeGripEnabled(False)
#        print(self.statusBar().layout() )
        self.statusBar().setStyleSheet("QStatusBar::item {border: none;}")
        self.statusBar().addPermanentWidget(self.pb, 1)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    ui = MainWindow()
    ui.show()
    sys.exit(app.exec_())

2 个答案:

答案 0 :(得分:3)

只需设置

self.pb.setTextVisible(False)

答案 1 :(得分:0)

我认为这可以解决您的问题。

    import sys
    from PyQt4.QtGui import *
    from PyQt4.QtCore import *

    class MainWindow(QMainWindow):

        def __init__(self, parent=None):
            super(MainWindow, self).__init__(parent)

            self.pb = QProgressBar()
            # To make the text visible, you must not setRange(0, 0) and
            # you must setValue(something valid). Otherwise, the text is
            # hidden.
            #
            # In the default Windows style, the blank space to the right
            # of the progress bar is room for this text. Calling
            # setTextVisible(False) removes this space. Other styles will
            # place the text in the middle of the progress bar.
            #
            # Unfortunately, I don't see any (simply) way to display a
            # spinning progres bar AND text at the same time.
            self.pb.setRange(0, 9)
            self.pb.setValue(1)
            self.pb.setFormat('finding resource...')

            self.statusBar().setSizeGripEnabled(False)
            self.statusBar().addPermanentWidget(self.pb, 1)


    if __name__ == "__main__":
        app = QApplication(sys.argv)

        ui = MainWindow()
        ui.show()
        sys.exit(app.exec_())