Custom QEvent question
-
It seems like I must be missing something staggeringly obvious. Custom events, clearly visible in a QWidget's event method if I override it to take a look, never reach the customEvent method. Simply adding
if event.type() >= QEvent.User: self.customEvent(event)
to event makes everything work the way I expect it to. Is there some QApplication flag I need to set? All the Qt documentation indicates it is just a matter of setting the event type properly and overriding customEvent. Was customEvent secretly deprecated when QCustomEvent was? Feel like I'm going mad :-)
-- an infrequent Qt user
(Not that it should matter but obv. using Python binding)
-
@krm26 said in Custom QEvent question:
if I override it to take a look,
What do you mean with this? What do you override where?
-
@Christian-Ehrlicher I mean if I override the event method in the object that I'm posting to I clearly see the posted custom event being properly dispatched. The customEvent method, however, is never called. Now, as I understand the architecture, it is expected for the event method to see (and ignore) custom events -- but it is also expected for the customEvent method to see them and house your custom event-handling logic.
-
Hi,
Looks like you are using python. Which bindings are you using ?
Can you provide a minimal runnable example that shows your issue ?
-
All is correct. QObject::event() is called for every event, QObject::customEvent() only for custom events.
-
@Christian-Ehrlicher What I said is that QObject.customEvent is NOT being called for custom events. QObject.event sees the custom events (and ignores them in its default implementation), QObject.customEvent is never called.
Guess I'll source-dive the answer, thanks.
-
@krm26 said in Custom QEvent question:
Guess I'll source-dive the answer, thanks.
Not needed and I don't think you're right except somehwere else the event is already accepted:
https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qobject.cpp.html#1298I would guess you simply forget to call the base class event() function when you've overwritten it.