Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qabstractnativeeventfilter.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
9
10/*!
11 \class QAbstractNativeEventFilter
12 \inmodule QtCore
13 \since 5.0
14
15 \brief The QAbstractNativeEventFilter class provides an interface for receiving native
16 events, such as MSG or XCB event structs.
17*/
18
19/*!
20 Creates a native event filter.
21
22 By default this doesn't do anything. Remember to install it on the application
23 object.
24*/
25QAbstractNativeEventFilter::QAbstractNativeEventFilter()
26{
27 Q_UNUSED(d);
28}
29
30/*!
31 Destroys the native event filter.
32
33 This automatically removes it from the application.
34*/
35QAbstractNativeEventFilter::~QAbstractNativeEventFilter()
36{
37 QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
38 if (eventDispatcher)
39 eventDispatcher->removeNativeEventFilter(this);
40}
41
42/*!
43 \fn bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
44
45 This method is called for every native event.
46
47 \note The filter function here receives native messages,
48 for example, MSG or XCB event structs.
49
50 It is called by the QPA platform plugin. On Windows, it is called by
51 the event dispatcher.
52
53 The type of event \a eventType is specific to the platform plugin chosen at run-time,
54 and can be used to cast \a message to the right type.
55
56 On X11, \a eventType is set to "xcb_generic_event_t", and the \a message can be casted
57 to a xcb_generic_event_t pointer.
58
59 On Windows, \a eventType is set to "windows_generic_MSG" for messages sent to toplevel windows,
60 and "windows_dispatcher_MSG" for system-wide messages such as messages from a registered hot key.
61 In both cases, the \a message can be casted to a MSG pointer.
62 The \a result pointer is only used on Windows, and corresponds to the LRESULT pointer.
63
64 On macOS, \a eventType is set to "mac_generic_NSEvent", and the \a message can be casted to an NSEvent pointer.
65
66 In your reimplementation of this function, if you want to filter
67 the \a message out, i.e. stop it being handled further, return
68 true; otherwise return false.
69
70 \b {Linux example}
71 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.cpp 0
72
73 \b {Windows example}
74 \snippet code/src_corelib_kernel_qabstractnativeeventfilter_win.cpp 0
75
76 \b {macOS example}
77
78 mycocoaeventfilter.h:
79 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.mm mycocoaeventfilter
80
81 mycocoaeventfilter.mm:
82 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.mm include
83 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.mm 0
84
85 myapp.pro:
86 \snippet code/src_corelib_kernel_qabstractnativeeventfilter.pro 0
87*/
88
89QT_END_NAMESPACE
Combined button and popup list for selecting options.