Consider the following toy example:
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_()
How can I expand the letters of toyLabel
without distorting it?
When using setStretch()
as above the result is a mess:
I have also tried to expand the letters using a font-stretch
property in a stylesheet but this is not supported.
Apparently, this can be set directly in the font
stylesheet property:
QLabel {
font: 12px Times Expanded;
}