Font families are truncated

Charles peacech at gmail.com
Fri Nov 15 04:35:46 GMT 2024


That is the limitation of using GDI font engine. If you are using Qt>=6.7,
trying using -platform windows:fontengine=directwrite command line
parameter.

On Fri, Nov 15, 2024 at 10:12 AM John F Sturtz <john at sturtz.org> wrote:

> 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/20241115/5c91d399/attachment.htm>


More information about the PyQt mailing list