PyQt6 and invalid enums: QKeySequence/QKeyCombination

Florian Bruhin me at
Thu Apr 28 18:18:21 BST 2022


I wanted to report another case where I see invalid enum ValueErrors
from PyQt6 without doing anything wrong. Not sure if this changes
anything about the big picture, but maybe it does, given that the
underlying issue is a bit different:

    >>> qkeycombination = QKeySequence("\x80")[0]
    >>> qkeycombination.key()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.10/", line 385, in __call__
        return cls.__new__(cls, value)
      File "/usr/lib/python3.10/", line 710, in __new__
        raise ve_exc
    ValueError: 128 is not a valid Qt.Key

I think Qt.Key is special in that regard because unicode characters
(at least those not represented in the enum) just end up as a
pseudo-member of that enum:

This seems reflected in some places of the Qt API (I think that's why
e.g. QKeyEvent.key() returns an int, not a Qt.Key), but evidently not in
others (QKeyCombination.key() in this case).


            me at | |
       GPG: 916E B0C8 FD55 A072 |
             I love long mails! |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <>

More information about the PyQt mailing list