我希望进度条扩展到状态栏的整个宽度,但为什么那里有间隙?我可以在进度条上添加一些文本吗,没有像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_())
刚刚设置
self.pb.setTextVisible(False)
我认为这可以解决您的问题。
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_())