Can't expand the progress bar to full width of the status bar

I want the progress bar to expand to the full width of the status bar, but why is there a space in there? PS. can i add some text to the progress bar, there is no function like setText (), how can i do that?

Is there a widget or something else there?

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_())

      

+3


source to share


2 answers


just install



self.pb.setTextVisible(False)

      

+3


source


I think this solves your problem.



    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_())

      

0


source







All Articles