Another PyQt6 oddity

Detlev Offenbach detlev at die-offenbachs.de
Wed May 19 15:57:30 BST 2021


Hi Phil,

I investigated this issue a bit further and have to let you know, that 
the cause is located inside QScintilla (several places). In the code you 
find lines to set the font weight with

     // Pass the Qt weight via the back door.
     SendScintilla(SCI_STYLESETWEIGHT, style, -f.weight());

This causes the trouble because Qt6 uses different font weight values 
than Qt5. The later orients the font weight on the usual window systems. 
The following examples show the difference.

##################################
## PyQt5
##################################

 >>> from PyQt5.QtGui import QFont
 >>> f=QFont("Arial")
 >>> f
<PyQt5.QtGui.QFont object at 0x0000000002FDE3C0>
 >>> f.weight()
50
 >>> fw = f.weight()
 >>> type(fw)
<class 'int'>
 >>> f.setBold(True)
 >>> f.weight()
75

##################################
## PyQt6
##################################

 >>> from PyQt6.QtGui import QFont
 >>> f=QFont("Arial")
 >>> f
<PyQt6.QtGui.QFont object at 0x0000000002EED430>
 >>> f.weight()
400
 >>> fw = f.weight()
 >>> type(fw)
<class 'int'>
 >>> f.setBold(True)
 >>> f.weight()
700

The net result is, that the QScintilla font weight for a bold font 
(actually all fonts) is set to a value >= 100, which is dark black. To 
solve this, you have to translate the Qt6 font weight to the Qt5 values. 
I tried this within eric7 and it works for the particular case.

I hope this helps to get the issue resolved.

Regards,
Detlev

Am 17.05.21 um 17:10 schrieb Phil Thompson:
> On 17/05/2021 15:58, Detlev Offenbach wrote:
>> Hello,
>>
>> I am in the process of porting eric to PyQt6. During this process I
>> observed, that the text of the PyQt6 variant of QScintilla is always
>> shown with a bold font (see attached screenshot) although only a few
>> style are configured to use bold font. The same applies to the line
>> numbers, which should be shown with a regular font. What am I doing
>> wrong?
>>
>> Note: I checked the saved styles in the QSettings file and they are
>> all correct in there.
>
> The values of the QFont Weight enum have changed between Qt5 and Qt6 
> so if you are saving the numerical value (rather than a symbolic name) 
> in the settings then that might be the problem.
>
> Compare...
>
> https://doc.qt.io/qt-5/qfont.html#Weight-enum
> https://doc.qt.io/qt-6/qfont.html#Weight-enum
>
> Phil

-- 
Detlev Offenbach
detlev at die-offenbachs.de



More information about the PyQt mailing list