直接展示代码:在程序初始化时,直接调用该方法就可以,代码中有两种布局方式,一种是靠左侧布局,一种是靠右侧布局。
# 初始化状态栏
def initStatusBar(self):
# 定义文本标签
self.statusLabel = QLabel()
# 设置文本标签显示内容
self.statusLabel.setText("Not running")
self.statusLabel.setObjectName('statusLabel')
# 定义水平进度条
self.progressBar = QProgressBar()
# 设置进度条的范围,参数1为最小值,参数2为最大值(可以调得更大,比如1000
self.progressBar.setRange(0, 100)
# 设置进度条的初始值
self.progressBar.setValue(66)
# 往状态栏中添加组件(stretch应该是拉伸组件宽度)-->会添加到状态栏左侧
self.statusbar.addWidget(self.statusLabel)
self.statusbar.addWidget(self.progressBar)
# 往状态栏中添加组件(stretch应该是拉伸组件宽度)-->会添加到状态栏的右侧
# self.statusbar.addPermanentWidget(self.statusLabel, stretch=2)
# self.statusbar.addPermanentWidget(self.progressBar, stretch=10)
# self.progressBar.hide()
参考: