PyQt5 bug in font settings

Colin McPhail mcphail_colin at hotmail.com
Wed Oct 7 12:21:21 BST 2020



> On 7 Oct 2020, at 09:33, ullix <ullix at urkam.de> wrote:
> 
> I believe I found a bug in PyQt5 (or QT?) , surfacing only under Windows, perhaps only Win10
> 
> The problem: A font may be set, and confirmed by PyQt5 to be in use, yet the actual font is a completely different one. I noticed this when I defined a fixed width font, but became a proportional font, despite PyQt5 telling it is Courier New.
> 
> More details already reported here:
> 
> https://stackoverflow.com/questions/64213031/python3-with-pyqt5-on-win10-ignores-font-settings
> 
> 
Hi,
Qt's documentation for QFont (https://doc.qt.io/qt-5/qfont.html <https://doc.qt.io/qt-5/qfont.html>) implies that a QFont instance records what you asked for rather than what font it selected:

When you create a QFont object you specify various attributes that you want the font to have. Qt will use the font with the specified attributes, or if no matching font exists, Qt will use the closest matching installed font. The attributes of the font that is actually used are retrievable from a QFontInfo <https://doc.qt.io/qt-5/qfontinfo.html> object. If the window system provides an exact match exactMatch <https://doc.qt.io/qt-5/qfont.html#exactMatch>() returns true.

If you create and interrogate a QFontInfo instance after creating your QFont then you can see how the font selection went. As to why you don't get the font you ask for on Windows 10, I'm afraid I can't help with that.

Regards,
Colin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20201007/69c861ed/attachment.htm>


More information about the PyQt mailing list