QFontDatabase/QFont question
John Sturtz
john at sturtz.org
Sat Jan 11 18:36:58 GMT 2025
I did actually delve into that a little bit. It seemed to be
unrewarding. My experience was as follows:
For all the fonts (that I looked) on my system, .variableAxisTags()
initially returns an empty list when a font object is created, both for
fonts that the Win font dialog reports as variable and ones that it
doesn't report as variable. For example, in both these cases:
f = QFontDatabase.font('Arial', 'Regular', 24)
print(f.variableAxisTags())
f = QFontDatabase.font('Exo', 'Thin', 24)
print(f.variableAxisTags())
the print() displays an empty list. Arial isn't variable, so I wouldn't
expect anything there. But Exo is, and the value for the 'wght' axis
for the font created should be 100 ('Thin'). But that doesn't affect
the list that .variableAxisTags() returns. So Qt doesn't seem to fill
that list; only user code apparently.
Setting the 'wght' variable axis with .setVariableAxis() does indeed
seem to work for Exo. This:
f = QFontDatabase.font('Exo', 'Regular', 24)
f.setVariableAxis(QtGui.QFont.Tag('wght'), 800)
print(f.variableAxisTags())
does display Exo ExtraBold. And the print() statement now shows a Tag
object in the list. (Oddly, though setting the 'wght' axis in this
manner worked as I expected, I couldn't get setting the 'ital' axis to
cause italic to be displayed ...)
Setting these axes for a font that is (according to Win settings) not
variable also adds an item to the variable axis tags list. This code
runs:
f = QFontDatabase.font('Arial', 'Regular', 24)
f.setVariableAxis(QtGui.QFont.Tag('wght'), 800)
print(f.variableAxisTags())
Here also, the print() statement displays a Tag item in the list. It
doesn't generate any sort of error, and by all appearances seems to
'succeed'. Of course, it doesn't change the font that's displayed,
because Arial isn't variable.
As far as I could tell, the only thing in the picture that would clue me
in that Exo is variable and Arial is not is that the .setVariableAxis()
call didn't change the appearance of the displayed font. But nothing
programmatically. It would be lovely if QFontDatabase or QFont had
something like .isVariable(), or some such. But evidently not ...
/John
------ Original Message ------
>From "Maurizio Berti" <maurizio.berti at gmail.com>
To "John Sturtz" <john at sturtz.org>
Cc "Charles" <peacech at gmail.com>; pyqt at riverbankcomputing.com
Date 1/11/2025 9:33:18 AM
Subject Re: Re[6]: QFontDatabase/QFont question
>I've not used variable fonts yet, but you should probably start by
>inspecting the QFont instance using the related "variable" and "tag"
>functions introduced in 6.7, such as
>https://doc.qt.io/qt-6/qfont.html#variableAxisTags
>Maybe you can create a small program that lists all fonts and the
>results of those functions, then compare it with the Windows font
>dialog.
>
>Cheers,
>MaurizioB
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20250111/ca6588cb/attachment.htm>
More information about the PyQt
mailing list