Font families are truncated

Charles peacech at gmail.com
Fri Nov 15 05:27:07 GMT 2024


If your Qt is compiled with freetype, you can try using it instead, see

https://doc.qt.io/qt-5/qt-conf.html (bottom of page)
https://github.com/qt/qtbase/blob/v5.15.14-lts-lgpl/src/plugins/platforms/windows/qwindowsintegration.cpp#L189

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

> Alas.  Still working in (Py)Qt5.  I'm probably stuck with it then.
>
> Thanks.
>
> /John
>
> Charles <peacech at gmail.com>
> Thursday, November 14, 2024 10:35 PM
> 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.
>
> John F Sturtz <john at sturtz.org>
> Thursday, November 14, 2024 9:12 PM
> 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/0c87bca9/attachment.htm>


More information about the PyQt mailing list