#[repr(C)]
pub struct QAbstractNativeEventFilter { /* private fields */ }
Expand description

The QAbstractNativeEventFilter class provides an interface for receiving native events, such as MSG or XCB event structs.

C++ class: QAbstractNativeEventFilter.

C++ documentation:

The QAbstractNativeEventFilter class provides an interface for receiving native events, such as MSG or XCB event structs.

Implementations§

source§

impl QAbstractNativeEventFilter

source

pub unsafe fn native_event_filter( &self, event_type: impl CastInto<Ref<QByteArray>>, message: *mut c_void, result: *mut c_long ) -> bool

This method is called for every native event.

Calls C++ function: pure virtual bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray& eventType, void* message, long* result).

C++ documentation:

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 eventType is specific to the platform plugin chosen at run-time, and can be used to cast message to the right type.

On X11, eventType is set to "xcb_generic_event_t", and the message can be casted to a xcb_generic_event_t pointer.

On Windows, eventType is 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, the message can be casted to a MSG pointer. The result pointer is only used on Windows, and corresponds to the LRESULT pointer.

On macOS, eventType is set to "mac_generic_NSEvent", and the message can be casted to an NSEvent pointer.

In your reimplementation of this function, if you want to filter the message out, 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:

HEADERS += mycocoaeventfilter.h OBJECTIVE_SOURCES += mycocoaeventfilter.mm LIBS += -framework AppKit

Trait Implementations§

source§

impl CppDeletable for QAbstractNativeEventFilter

source§

unsafe fn delete(&self)

Destroys the native event filter.

Calls C++ function: virtual [destructor] void QAbstractNativeEventFilter::~QAbstractNativeEventFilter().

C++ documentation:

Destroys the native event filter.

This automatically removes it from the application.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.