PyQt6: Cannot create new custom QEvent

Ales Erjavec ales.erjavec324 at gmail.com
Mon Apr 19 14:25:25 BST 2021


On Mon, Apr 19, 2021 at 3:15 PM Colin McPhail <colin.mcphail at mac.com> wrote:
>
> Hi,
>
> On 19 Apr 2021, at 13:18, Ales Erjavec <ales.erjavec324 at gmail.com> wrote:
>
> Hi,
>
> In PyQt6 this fails with a type error:
> ```
> from PyQt6.QtCore import QEvent
>
> class CustomEvent(QEvent):
>    EventType = QEvent.registerEventType()
>    def __init__(self):
>        super().__init__(CustomEvent.EventType)  # << Error Here
>
> ev = CustomEvent()
> ev.type()
> ```
> because the QEvent.__init__ arg must be QEvent.Type; in PyQt6 this is
> an python enum and cannot represent 'undeclared' values).
>
>
> I believe QEvent.registerEventType() returns an integer not a QEvent.Type instance. If you modify that line like:
>    EventType = QEvent.Type(QEvent.registerEventType())
> then I think it might be accepted.
>
> Regards,
> -- Colin

No. I a fresh session:
QEvent.Type(QEvent.registerEventType())  == QEvent.MaxUser
QEvent.Type(QEvent.registerEventType()) ## raises ValueError: 65533 is
not a valid Type


More information about the PyQt mailing list