PyQt5 bug in font settings

Dennis Jensen djensen at pgcontrols.com
Wed Oct 7 15:31:07 BST 2020


Instead of using QFont try using the CSS (or QSS) to set the font

On 10/7/2020 8:42 AM, ullix wrote:
>
> hen 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|.
>
> ... and this is what I intended and it worked correctly until recently 
> (on Linux it still works.)
>
> But even stranger: when all I define (on Windows) is 'self.fontstd = 
> QFont("Consolas", 10)',
>
> the fontifnfo result is:
>
> -Family:Consolas, fixed:True, size:10, style:0, styleHint:5, 
> styleName:, weight:50, exactMatch:False
>
> Note that it matches all request, yet the exactMatch comes as false?
>
>
> Am 07.10.20 um 13:21 schrieb Colin McPhail:
>>
>>
>>> On 7 Oct 2020, at 09:33, ullix <ullix at urkam.de 
>>> <mailto: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) 
>> 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/addc23c5/attachment.htm>


More information about the PyQt mailing list