PyQt6: Cannot create new custom QEvent

Colin McPhail colin.mcphail at mac.com
Mon Apr 19 14:15:52 BST 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210419/db9d9d5f/attachment.htm>


More information about the PyQt mailing list