PyQt6: Cannot create new custom QEvent
Phil Thompson
phil at riverbankcomputing.com
Mon Apr 19 14:30:39 BST 2021
On 19/04/2021 14:15, Colin McPhail 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.
That will work but only because the value corresponds to MaxUser (Qt
allocates types from there working downwards). It won't work if you
register a second type (ie. MaxUser - 1) which does not have a
corresponding 'declared' value.
It will be fixed in the next snapshot.
Phil
More information about the PyQt
mailing list