Mir ist bei folgendem Code aufgefallen, dass bei unterschiedlichen Fontgrößen, immer die gleiche Texthöhe ich bei QFont erhalte.
Vielleicht könnt Ihr mir dabei helfen, dies zu lösen!
Code: Alles auswählen
import sys
from PyQt5.QtWidgets import (
QApplication,
)
from PyQt5.QtGui import (
QFont,
QFontMetrics,
QFontMetricsF
)
if __name__ == '__main__':
app = QApplication(sys.argv)
text_string = 'Text'
font_size = 10
f = QFont()
f.setFamily('NimbusSansL')
f.setWeight(int(font_size))
fm = QFontMetricsF(f)
text_height = fm.height()
text_width = fm.width(text_string)
print('text_height: ', text_height)
print('text_width: ', text_width)