python - PyQt5 StatusBar 分隔符

标签 python python-3.x pyqt pyqt5

如何向状态栏添加垂直分隔符?

此屏幕截图中的

(红色箭头)

enter image description here

如果我成功了,我如何显示选定的

同一屏幕截图中的

(蓝色箭头)

这是针对 Windows 的。

最佳答案

void QStatusBar::addPermanentWidget(QWidget *widget, int stretch = 0)

Adds the given widget permanently to this status bar, reparenting the widget if it isn't already a child of this QStatusBar object. The stretch parameter is used to compute a suitable size for the given widget as the status bar grows and shrinks. The default stretch factor is 0, i.e giving the widget a minimum of space.

import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QStatusBar, QLabel, 
                             QPushButton, QFrame)

class VLine(QFrame):
    # a simple VLine, like the one you get from designer
    def __init__(self):
        super(VLine, self).__init__()
        self.setFrameShape(self.VLine|self.Sunken)

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.statusBar().showMessage("bla-bla bla")
        self.lbl1 = QLabel("Label: ")
        self.lbl1.setStyleSheet('border: 0; color:  blue;')
        self.lbl2 = QLabel("Data : ")
        self.lbl2.setStyleSheet('border: 0; color:  red;')
        ed = QPushButton('StatusBar text')

        self.statusBar().reformat()
        self.statusBar().setStyleSheet('border: 0; background-color: #FFF8DC;')
        self.statusBar().setStyleSheet("QStatusBar::item {border: none;}") 
        
        self.statusBar().addPermanentWidget(VLine())    # <---
        self.statusBar().addPermanentWidget(self.lbl1)
        self.statusBar().addPermanentWidget(VLine())    # <---
        self.statusBar().addPermanentWidget(self.lbl2)
        self.statusBar().addPermanentWidget(VLine())    # <---
        self.statusBar().addPermanentWidget(ed)
        self.statusBar().addPermanentWidget(VLine())    # <---
        
        self.lbl1.setText("Label: Hello")
        self.lbl2.setText("Data : 15-09-2019")

        ed.clicked.connect(lambda: self.statusBar().showMessage("Hello "))
        
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())

enter image description here

关于python - PyQt5 StatusBar 分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57943862/

相关文章:

python - 是否有更快的方法来查找数据框中常量值的范围?

python - 返回节点邻域中最大的节点

python - 使用 python 和 selenium 未选择选择类型

python - 当模型增长时,让 QTableView 滚动到最后一行

python - Pandas:根据索引添加行

python - 简单利用 "import as"加载多场景数据?

python - 如何处理输出文件的区分大小写排序?

Python:定义具有依赖属性的类

python - 更新 PyQt 菜单

python - Qml中的PyQt5 ApplicationWindow获取黑屏