Font families are truncated

John F Sturtz john at sturtz.org
Fri Nov 15 03:12:36 GMT 2024


Greetings again!

This is perhaps a bit of an esoteric question.

I am using QFontDatabase and QFont to query and manipulate some display 
fonts.  On my system, there are some font family/variant combinations 
that have pretty long names.  Several in the Bahnschrift family, for 
instance -- Bahnschrift SemiBold SemiCondensed, Bahnschrift SemiLight 
SemiCondensed, and so on.

The Windows font settings app lists these with their full names.  Also, 
if I query the .ttf file directly:

     path = r'C:\Windows\fonts\bahnschrift.ttf'
     font = ttLib.TTFont(path)
     for instance in font["fvar"].instances:
         style = font["name"].getName(instance.subfamilyNameID, 3, 1, 0x409)
         print(style)

I get the full names.

However, if I get a list of font families using 
QFontDatabase().families(), the names that are returned are truncated to 
(oddly) 31 characters.  So, for example, Bahnschrift SemiBold 
SemiConden, Bahnschrift SemiLight SemiConde, and the like.

And indeed, if I want to create a QFont object for these, I seem to need 
to use the truncated names:

QFont('Bahnschrift SemiBold SemiConden')        # These work
QFont('Bahnschrift SemiLight SemiConde')

QFont('Bahnschrift SemiBold SemiCondensed')     # These do not
QFont('Bahnschrift SemiLight SemiCondensed')

Not a huge deal, but it's a little difficult, because the names PyQt 
seems to recognize aren't the ones I'd want to present to the user (nor 
ones I would have thought to use, but for the fact that 
QFontDatabase().families() gave them to me that way).  Any thoughts as 
to why?

Thanks again, as always!

/John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20241114/4ad85f36/attachment.htm>


More information about the PyQt mailing list