QAbstractNativeEventFilter¶
The
QAbstractNativeEventFilterclass provides an interface for receiving native events, such as MSG or XCB event structs. More…

Detailed Description¶
- class PySide2.QtCore.QAbstractNativeEventFilter¶
Creates a native event filter.
By default this doesn’t do anything. Remember to install it on the application object.
- PySide2.QtCore.QAbstractNativeEventFilter.nativeEventFilter(eventType, message)¶
- Parameters:
eventType –
PySide2.QtCore.QByteArraymessage –
void
- Return type:
PyObject
This method is called for every native event.
Note
The filter function here receives native messages, for example, MSG or XCB event structs.
It is called by the QPA platform plugin. On Windows, it is called by the event dispatcher.
The type of event
eventTypeis specific to the platform plugin chosen at run-time, and can be used to castmessageto the right type.On X11,
eventTypeis set to “xcb_generic_event_t”, and themessagecan be casted to a xcb_generic_event_t pointer.On Windows,
eventTypeis set to “windows_generic_MSG” for messages sent to toplevel windows, and “windows_dispatcher_MSG” for system-wide messages such as messages from a registered hot key. In both cases, themessagecan be casted to a MSG pointer. Theresultpointer is only used on Windows, and corresponds to the LRESULT pointer.On macOS,
eventTypeis set to “mac_generic_NSEvent”, and themessagecan be casted to an NSEvent pointer.In your reimplementation of this function, if you want to filter the
messageout, i.e. stop it being handled further, return true; otherwise return false.Linux example
class MyXcbEventFilter : public QAbstractNativeEventFilter { public: bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override { if (eventType == "xcb_generic_event_t") { xcb_generic_event_t* ev = static_cast<xcb_generic_event_t *>(message); // ... } return false; } };
macOS example
mycocoaeventfilter.h:
#include <QAbstractNativeEventFilter> class MyCocoaEventFilter : public QAbstractNativeEventFilter { public: bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override; };
mycocoaeventfilter.mm:
#include "mycocoaeventfilter.h" #import <AppKit/AppKit.h> bool CocoaNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *) { if (eventType == "mac_generic_NSEvent") { NSEvent *event = static_cast<NSEvent *>(message); if ([event type] == NSKeyDown) { // Handle key event qDebug() << QString::fromNSString([event characters]); } } return false; }
myapp.pro:
<Code snippet "code/src_corelib_kernel_qabstractnativeeventfilter.pro:0" not found>
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.