PyQt6: QEvent.type() returns int instead of QEvent.Type

Florian Bruhin me at the-compiler.org
Thu Apr 21 10:37:03 BST 2022


Hey,

With PyQt5:

    >>> evtype = QEvent(QEvent.Type.User).type()
    >>> evtype
    1000
    >>> type(evtype)
    <class 'PyQt5.QtCore.QEvent.Type'>

and even:

    >>> evtype = QEvent(QEvent.Type.User + 1).type()
    >>> evtype
    1001
    >>> type(evtype)
    <class 'PyQt5.QtCore.QEvent.Type'>

but with PyQt6, the type information gets lost:

    >>> evtype = QEvent(QEvent.Type.User).type()
    >>> evtype
    1000
    >>> type(evtype)
    <class 'int'>

From what I understand, it's not possible to convert arbitrary values
into an IntEnum:

    >>> QEvent.Type(QEvent.Type.User + 1)
    [...]
    ValueError: 1001 is not a valid QEvent.Type

But least for types which are part of QEvent.Type, calling .type()
should perhaps return the IntEnum value again instead of falling back to
an int without any type information? Given that IntEnum is an int
subclass, this should be a backwards-compatible change too.

Florian

-- 
            me at the-compiler.org | https://www.qutebrowser.org 
       https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
       GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
             I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220421/d7d5c83f/attachment.sig>


More information about the PyQt mailing list