QFontDatabase/QFont question
John Sturtz
john at sturtz.org
Sat Jan 11 01:00:55 GMT 2025
------ Original Message ------
>From "Charles" <peacech at gmail.com>
To "John Sturtz" <john at sturtz.org>
Cc "Maurizio Berti" <maurizio.berti at gmail.com>;
pyqt at riverbankcomputing.com
Date 1/9/2025 10:55:57 PM
Subject Re: Re[2]: QFontDatabase/QFont question
> > you're getting a named style from the variable font file
>
>You didn't mention that you are using the variable font. I didn't use
>the variable font instead I use the static fonts. I also got the thin
>oblique font with the variable fonts.
I thought the font was inherently variable? Or is it a matter of how
you access it? Use QFontDatabase() (accessing by style name), and you
are using it as a variable font; use QFont + .setWeight() and
.setItalic() methods, and you are using it as static (= 'simulated' =
'synthesized'). Do I understand that correctly?
>
>These codes works for me:
>
>1. f = QFont('Exo', 24, 700, True) # use QFont specifying weight and
>italic
>2. f = QFont('Exo', 24); f.setWeight(700); f.setItalic(True)
>3. f = QFontDatabase('Exo', 'Bold', 24); f.setStyleName('Bold Italic')
Yes, these all work for me as well [the last needs to be
QFontDatabase.font('Exo', 'Bold', 24)]
>Note that italic is part of the style name. If you call setItalic(True)
>there is a mismatch between the style flags and the style name. So if
>you use QFontDatabase and style name always use setStyleName to change
>the style, otherwise use QFont and setWeight and setItalic.
So it seems the moral is not to intermingle QFont (static) and
QFontDatabase (variable) methods.
But this case still troubles me:
I see the problem with other fonts as well -- Bahnschrift, for example,
which comes with Windows. If I create a QFont object with
QFontDatabase.font():
f = QFontDatabase.font('Bahnschrift', 'Condensed', 24)
and then apply .setItalic(True) to it, it's italic, but no longer
Condensed.
And actually, the same thing happens if I create the font with QFont()
directly:
f = QFont(
'Bahnschrift Condensed',
pointSize=24
)
Here also, the font is fine initially, but after .setItalic(True) it is
no longer Condensed.
QFontDatabase offers no italic style for Bahnschrift Condensed. If I
create with QFont(), it is initially condensed. But if I call
.setItalic(True), it no longer is condensed; it's just plain
Bahnschrift.
I'd think this must be a bug?
/John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20250111/64ffa104/attachment.htm>
More information about the PyQt
mailing list