如何使QLabel的边框看起来像QTreeWidget等其他小部件的边框?

时间:2017-06-14 21:32:01

标签: python qt pyqt pyqt4 pyqt5

我注意到QTreeWidget和QLabel的不同边框样式 - 即使我尝试调整样式表。当然,我可以更改两者的样式表,但理想情况下我希望保留QTreeWidget的边框样式。如何使QLabel的边框看起来像QTreeWidget的边框?

MCVE片段:

import sys
from PyQt5.QtWidgets import *

class widget(QWidget):
    def __init__(self):
        super().__init__()
        treewidget = QTreeWidget(self)
        label = QLabel(self)
        label.setStyleSheet("background-color: white; border: 1px inset grey; min-height: 200px;")
        grid = QGridLayout()
        grid.setSpacing(10)
        grid.addWidget(treewidget, 1, 0)
        grid.addWidget(label, 2, 0)
        self.setLayout(grid)
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    f = widget()
    sys.exit(app.exec_())

没有样式表:

window default

MCVE代码段生成窗口的屏幕截图:

window as is

我希望窗口看起来像是什么:

window as desired

1 个答案:

答案 0 :(得分:2)

你可能已经找到了答案,但以防万一......

以下内容可为您提供所需内容......

std::reference_wrapper<BlackListEdgeConstraint>

我刚刚将线宽硬连线。请注意,“border:1px”说明符必须从样式表中删除,否则将优先使用它来指定的行宽。完整的代码将是......

label = QLabel(self)
label.setFrameShape(QFrame.Panel)
label.setFrameShadow(QFrame.Sunken)
label.setLineWidth(3)