PyQt6 QWidget.keyPressEvent() behaviour changed?

Baz Walter bazwal at gmail.com
Tue Nov 16 15:32:08 GMT 2021


On 16/11/2021 12:34, Marko Luther wrote:
> with below example code I observe a difference between PyQt6 and PyQt5 in the result of the QKeyEvent delivered by the keyPressEvent method of QWidget.
> 
> While in PyQt5 the event.key() value did not change on pressing a modifier key together with another key, while in PyQt6 it does. Thus a simple comparison like event.key() == Qt.Key.Key_H does not work to recognise if the H key is pressed independent of modifier keys.
> 
> Is this intentional? How would one recognise the press of the H-key independent of any modifier?

On my Linux system, I see this:

# PyQt6 - Alt
72 h False True
16777251  True False
72 h True True

# PyQt5 - Alt
72 h False True
16777251  True False
72 h True True

# PyQt6 - AltGr
72 h False True
16781571  False False
294 ħ False False

# PyQt5 - AltGr
72 h False True
16781571  False False
294 ħ False False

Thus, when a modifier produces different text, a different key is returned. The same behaviour is seen with Shift - if I 
press e.g. Shift+5, the returned key is 37 (%), not 53 (5). The only exception to this is with upper/lower case letters, 
which always return the same key.

Given that, I would expect the character ª to return 170, not 72. In which case, the Qt6 behaviour on your system seems 
right to me, and the Qt5 behaviour seems wrong.

What specific versions of Qt5/6 are you using, and on what version of MacOS?


More information about the PyQt mailing list