扩展标签字符

问题描述 投票:0回答:1

请考虑以下玩具示例:

from PyQt5 import QtWidgets, QtGui

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        self.w = QtWidgets.QWidget()
        layout = QtWidgets.QVBoxLayout()
        self.w.setLayout(layout)
        self.setCentralWidget(self.w)

        toyLabel = QtWidgets.QLabel("Hello!")
        layout.addWidget(toyLabel)

        font = QtGui.QFont("Times", 16, QtGui.QFont.Bold)
        font.setStretch(150)
        toyLabel.setFont(font)

if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    window = MainWindow()
    window.show()
    app.exec_()

如何扩展toyLabel的字母而不会使其失真?

如上所述使用setStretch()时,结果是一团糟:

enter image description here

我也尝试过使用样式表中的font-stretch属性来扩展字母,但是不支持。

python python-3.x pyqt5 pyside2
1个回答
0
投票
显然,这可以直接在font样式表属性中设置:

QLabel { font: 12px Times Expanded; }

© www.soinside.com 2019 - 2024. All rights reserved.