QEvent class is the base class of all event classes. Event objects contain event parameters. 更多...
Header: | #include <QEvent> |
qmake: | QT += core |
继承者: |
QChildEvent , QDynamicPropertyChangeEvent , QStateMachine::SignalEvent , QStateMachine::WrappedEvent ,和 QTimerEvent |
enum | Type { None, ActionAdded, ActionChanged, ActionRemoved, ..., MaxUser } |
QEvent (QEvent::Type type ) | |
virtual | ~QEvent () |
void | accept () |
void | ignore () |
bool | isAccepted () const |
void | setAccepted (bool accepted ) |
bool | spontaneous () const |
QEvent::Type | type () const |
int | registerEventType (int hint = -1) |
const QMetaObject | staticMetaObject |
QEvent class is the base class of all event classes. Event objects contain event parameters.
Qt 的主事件循环 ( QCoreApplication::exec ()) 从事件队列抓取本机窗口系统事件,将它们转换成 QEvent,然后把翻译事件发送给 QObject s.
通常,事件来自底层窗口系统 (
spontaneous
() 返回
true
),但也可能手动发送事件使用
QCoreApplication::sendEvent
() 和
QCoreApplication::postEvent
() (
spontaneous
() 返回
false
).
QObjects 接收事件通过让其 QObject::event () 函数被调用。函数可以在子类中被重实现,以定制事件处理并添加额外事件类型; QWidget::event () 是显著范例。默认情况下,事件被分派给事件处理程序像 QObject::timerEvent () 和 QWidget::mouseMoveEvent (). QObject::installEventFilter () 允许对象拦截另一对象的预定事件。
The basic QEvent contains only an event type parameter and an "accept" flag. The accept flag set with accept (),而清零采用 ignore ()。它是默认设置,但不依赖于此,因为子类可能在其构造函数中选择清零它。
Subclasses of QEvent contain additional parameters that describe the particular event.
另请参阅 QObject::event (), QObject::installEventFilter (), QCoreApplication::sendEvent (), QCoreApplication::postEvent (),和 QCoreApplication::processEvents ().
此枚举类型定义 Qt 中的有效事件类型。事件类型和用于每个类型的专用类如下:
常量 | 值 | 描述 |
---|---|---|
QEvent::None
|
0
|
不是事件。 |
QEvent::ActionAdded
|
114
|
新的动作已被添加 ( QActionEvent ). |
QEvent::ActionChanged
|
113
|
动作已被改变 ( QActionEvent ). |
QEvent::ActionRemoved
|
115
|
动作已被移除 ( QActionEvent ). |
QEvent::ActivationChange
|
99
|
Widget 的顶层窗口激活状态已更改。 |
QEvent::ApplicationActivate
|
121
|
此枚举已弃用。使用 ApplicationStateChange 代替。 |
QEvent::ApplicationActivated
|
ApplicationActivate
|
此枚举已弃用。使用 ApplicationStateChange 代替。 |
QEvent::ApplicationDeactivate
|
122
|
此枚举已弃用。使用 ApplicationStateChange 代替。 |
QEvent::ApplicationFontChange
|
36
|
默认应用程序字体已改变。 |
QEvent::ApplicationLayoutDirectionChange
|
37
|
默认的应用程序布局方向已改变。 |
QEvent::ApplicationPaletteChange
|
38
|
默认的应用程序调色板已改变。 |
QEvent::ApplicationStateChange
|
214
|
应用程序的状态已改变。 |
QEvent::ApplicationWindowIconChange
|
35
|
应用程序的图标已改变。 |
QEvent::ChildAdded
|
68
|
对象获取子级 ( QChildEvent ). |
QEvent::ChildPolished
|
69
|
Widget 子级被抛光 ( QChildEvent ). |
QEvent::ChildRemoved
|
71
|
对象失去子级 ( QChildEvent ). |
QEvent::Clipboard
|
40
|
剪贴板内容已改变。 |
QEvent::Close
|
19
|
Widget 被关闭 ( QCloseEvent ). |
QEvent::CloseSoftwareInputPanel
|
200
|
A widget wants to close the software input panel (SIP). |
QEvent::ContentsRectChange
|
178
|
The margins of the widget's content rect changed. |
QEvent::ContextMenu
|
82
|
上下文弹出菜单 ( QContextMenuEvent ). |
QEvent::CursorChange
|
183
|
Widget 的光标已改变。 |
QEvent::DeferredDelete
|
52
|
The object will be deleted after it has cleaned up (QDeferredDeleteEvent) |
QEvent::DragEnter
|
60
|
The cursor enters a widget during a drag and drop operation ( QDragEnterEvent ). |
QEvent::DragLeave
|
62
|
The cursor leaves a widget during a drag and drop operation ( QDragLeaveEvent ). |
QEvent::DragMove
|
61
|
A drag and drop operation is in progress ( QDragMoveEvent ). |
QEvent::Drop
|
63
|
A drag and drop operation is completed ( QDropEvent ). |
QEvent::DynamicPropertyChange
|
170
|
A dynamic property was added, changed, or removed from the object. |
QEvent::EnabledChange
|
98
|
Widget 的被启用状态已改变。 |
QEvent::Enter
|
10
|
鼠标进入 Widget 的边界 ( QEnterEvent ). |
QEvent::EnterEditFocus
|
150
|
An editor widget gains focus for editing.
QT_KEYPAD_NAVIGATION
must be defined.
|
QEvent::EnterWhatsThisMode
|
124
|
Send to toplevel widgets when the application enters "What's This?" mode. |
QEvent::Expose
|
206
|
Sent to a window when its on-screen contents are invalidated and need to be flushed from the backing store. |
QEvent::FileOpen
|
116
|
File open request ( QFileOpenEvent ). |
QEvent::FocusIn
|
8
|
Widget or Window gains keyboard focus ( QFocusEvent ). |
QEvent::FocusOut
|
9
|
Widget or Window loses keyboard focus ( QFocusEvent ). |
QEvent::FocusAboutToChange
|
23
|
Widget or Window focus is about to change ( QFocusEvent ) |
QEvent::FontChange
|
97
|
Widget 的字体已改变。 |
QEvent::Gesture
|
198
|
A gesture was triggered ( QGestureEvent ). |
QEvent::GestureOverride
|
202
|
A gesture override was triggered ( QGestureEvent ). |
QEvent::GrabKeyboard
|
188
|
Item gains keyboard grab ( QGraphicsItem only). |
QEvent::GrabMouse
|
186
|
项获得鼠标抓取 ( QGraphicsItem only). |
QEvent::GraphicsSceneContextMenu
|
159
|
Context popup menu over a graphics scene ( QGraphicsSceneContextMenuEvent ). |
QEvent::GraphicsSceneDragEnter
|
164
|
The cursor enters a graphics scene during a drag and drop operation ( QGraphicsSceneDragDropEvent ). |
QEvent::GraphicsSceneDragLeave
|
166
|
The cursor leaves a graphics scene during a drag and drop operation ( QGraphicsSceneDragDropEvent ). |
QEvent::GraphicsSceneDragMove
|
165
|
A drag and drop operation is in progress over a scene ( QGraphicsSceneDragDropEvent ). |
QEvent::GraphicsSceneDrop
|
167
|
A drag and drop operation is completed over a scene ( QGraphicsSceneDragDropEvent ). |
QEvent::GraphicsSceneHelp
|
163
|
The user requests help for a graphics scene ( QHelpEvent ). |
QEvent::GraphicsSceneHoverEnter
|
160
|
The mouse cursor enters a hover item in a graphics scene ( QGraphicsSceneHoverEvent ). |
QEvent::GraphicsSceneHoverLeave
|
162
|
The mouse cursor leaves a hover item in a graphics scene ( QGraphicsSceneHoverEvent ). |
QEvent::GraphicsSceneHoverMove
|
161
|
The mouse cursor moves inside a hover item in a graphics scene ( QGraphicsSceneHoverEvent ). |
QEvent::GraphicsSceneMouseDoubleClick
|
158
|
Mouse press again (double click) in a graphics scene ( QGraphicsSceneMouseEvent ). |
QEvent::GraphicsSceneMouseMove
|
155
|
Move mouse in a graphics scene ( QGraphicsSceneMouseEvent ). |
QEvent::GraphicsSceneMousePress
|
156
|
Mouse press in a graphics scene ( QGraphicsSceneMouseEvent ). |
QEvent::GraphicsSceneMouseRelease
|
157
|
Mouse release in a graphics scene ( QGraphicsSceneMouseEvent ). |
QEvent::GraphicsSceneMove
|
182
|
Widget was moved ( QGraphicsSceneMoveEvent ). |
QEvent::GraphicsSceneResize
|
181
|
Widget was resized ( QGraphicsSceneResizeEvent ). |
QEvent::GraphicsSceneWheel
|
168
|
Mouse wheel rolled in a graphics scene ( QGraphicsSceneWheelEvent ). |
QEvent::Hide
|
18
|
Widget 被隐藏 ( QHideEvent ). |
QEvent::HideToParent
|
27
|
子级 Widget 已隐藏。 |
QEvent::HoverEnter
|
127
|
鼠标光标进入悬停 Widget ( QHoverEvent ). |
QEvent::HoverLeave
|
128
|
鼠标光标离开悬停 Widget ( QHoverEvent ). |
QEvent::HoverMove
|
129
|
鼠标光标在悬停 Widget 内移动 ( QHoverEvent ). |
QEvent::IconDrag
|
96
|
The main icon of a window has been dragged away ( QIconDragEvent ). |
QEvent::IconTextChange
|
101
|
Widget's icon text has been changed. (Deprecated) |
QEvent::InputMethod
|
83
|
An input method is being used ( QInputMethodEvent ). |
QEvent::InputMethodQuery
|
207
|
A input method query event ( QInputMethodQueryEvent ) |
QEvent::KeyboardLayoutChange
|
169
|
The keyboard layout has changed. |
QEvent::KeyPress
|
6
|
键按下 ( QKeyEvent ). |
QEvent::KeyRelease
|
7
|
键释放 ( QKeyEvent ). |
QEvent::LanguageChange
|
89
|
应用程序翻译已改变。 |
QEvent::LayoutDirectionChange
|
90
|
布局的方向已改变。 |
QEvent::LayoutRequest
|
76
|
Widget layout needs to be redone. |
QEvent::Leave
|
11
|
鼠标离开 Widget 边界。 |
QEvent::LeaveEditFocus
|
151
|
An editor widget loses focus for editing. QT_KEYPAD_NAVIGATION must be defined. |
QEvent::LeaveWhatsThisMode
|
125
|
Send to toplevel widgets when the application leaves "What's This?" mode. |
QEvent::LocaleChange
|
88
|
系统区域设置已改变。 |
QEvent::NonClientAreaMouseButtonDblClick
|
176
|
A mouse double click occurred outside the client area ( QMouseEvent ). |
QEvent::NonClientAreaMouseButtonPress
|
174
|
A mouse button press occurred outside the client area ( QMouseEvent ). |
QEvent::NonClientAreaMouseButtonRelease
|
175
|
A mouse button release occurred outside the client area ( QMouseEvent ). |
QEvent::NonClientAreaMouseMove
|
173
|
A mouse move occurred outside the client area ( QMouseEvent ). |
QEvent::MacSizeChange
|
177
|
The user changed his widget sizes ( macOS only). |
QEvent::MetaCall
|
43
|
An asynchronous method invocation via QMetaObject::invokeMethod (). |
QEvent::ModifiedChange
|
102
|
Widgets modification state has been changed. |
QEvent::MouseButtonDblClick
|
4
|
再次按下鼠标 ( QMouseEvent ). |
QEvent::MouseButtonPress
|
2
|
鼠标按下 ( QMouseEvent ). |
QEvent::MouseButtonRelease
|
3
|
鼠标释放 ( QMouseEvent ). |
QEvent::MouseMove
|
5
|
鼠标移动 ( QMouseEvent ). |
QEvent::MouseTrackingChange
|
109
|
鼠标跟踪状态已改变。 |
QEvent::Move
|
13
|
Widget 的位置被改变 ( QMoveEvent ). |
QEvent::NativeGesture
|
197
|
The system has detected a gesture ( QNativeGestureEvent ). |
QEvent::OrientationChange
|
208
|
The screens orientation has changes (QScreenOrientationChangeEvent). |
QEvent::Paint
|
12
|
必要的屏幕更新 ( QPaintEvent ). |
QEvent::PaletteChange
|
39
|
Palette of the widget changed. |
QEvent::ParentAboutToChange
|
131
|
The widget parent is about to change. |
QEvent::ParentChange
|
21
|
The widget parent has changed. |
QEvent::PlatformPanel
|
212
|
A platform specific panel has been requested. |
QEvent::PlatformSurface
|
217
|
本机平台表面已被创建或即将被销毁 ( QPlatformSurfaceEvent ). |
QEvent::Polish
|
75
|
The widget is polished. |
QEvent::PolishRequest
|
74
|
The widget should be polished. |
QEvent::QueryWhatsThis
|
123
|
The widget should accept the event if it has "What's This?" help ( QHelpEvent ). |
QEvent::ReadOnlyChange
|
106
|
Widget's read-only state has changed (since Qt 5.4). |
QEvent::RequestSoftwareInputPanel
|
199
|
A widget wants to open a software input panel (SIP). |
QEvent::Resize
|
14
|
Widget's size changed ( QResizeEvent ). |
QEvent::ScrollPrepare
|
204
|
The object needs to fill in its geometry information ( QScrollPrepareEvent ). |
QEvent::Scroll
|
205
|
The object needs to scroll to the supplied position ( QScrollEvent ). |
QEvent::Shortcut
|
117
|
Key press in child for shortcut key handling ( QShortcutEvent ). |
QEvent::ShortcutOverride
|
51
|
在子级中按下键,为覆盖快捷键处理 (
QKeyEvent
)。当快捷键即将被触发时,
ShortcutOverride
被发送给活动窗口。这允许客户端 (如 Widget) 通过接受事件,以信号它们自己将处理快捷键。若快捷键覆盖被接受,事件作为常规键按下被交付给聚焦 Widget。否则,它触发快捷键动作,若存在的话。
|
QEvent::Show
|
17
|
Widget 被展示在屏幕上 ( QShowEvent ). |
QEvent::ShowToParent
|
26
|
子级 Widget 已被展示。 |
QEvent::SockAct
|
50
|
套接字被激活,用于实现 QSocketNotifier . |
QEvent::StateMachineSignal
|
192
|
交付给状态机的信号 ( QStateMachine::SignalEvent ). |
QEvent::StateMachineWrapped
|
193
|
事件是包裹器,即:包含另一事件 ( QStateMachine::WrappedEvent ). |
QEvent::StatusTip
|
112
|
A status tip is requested ( QStatusTipEvent ). |
QEvent::StyleChange
|
100
|
Widget 的样式已改变。 |
QEvent::TabletMove
|
87
|
Wacom 平板移动 ( QTabletEvent ). |
QEvent::TabletPress
|
92
|
Wacom tablet press ( QTabletEvent ). |
QEvent::TabletRelease
|
93
|
Wacom tablet release ( QTabletEvent ). |
QEvent::TabletEnterProximity
|
171
|
Wacom tablet enter proximity event ( QTabletEvent ), sent to QApplication . |
QEvent::TabletLeaveProximity
|
172
|
Wacom tablet leave proximity event ( QTabletEvent ), sent to QApplication . |
QEvent::TabletTrackingChange
|
219
|
The Wacom tablet tracking state has changed (since Qt 5.9). |
QEvent::ThreadChange
|
22
|
The object is moved to another thread. This is the last event sent to this object in the previous thread. See QObject::moveToThread (). |
QEvent::Timer
|
1
|
Regular timer events ( QTimerEvent ). |
QEvent::ToolBarChange
|
120
|
The toolbar button is toggled on macOS . |
QEvent::ToolTip
|
110
|
A tooltip was requested ( QHelpEvent ). |
QEvent::ToolTipChange
|
184
|
The widget's tooltip has changed. |
QEvent::TouchBegin
|
194
|
Beginning of a sequence of touch-screen or track-pad events ( QTouchEvent ). |
QEvent::TouchCancel
|
209
|
Cancellation of touch-event sequence ( QTouchEvent ). |
QEvent::TouchEnd
|
196
|
End of touch-event sequence ( QTouchEvent ). |
QEvent::TouchUpdate
|
195
|
Touch-screen event ( QTouchEvent ). |
QEvent::UngrabKeyboard
|
189
|
Item loses keyboard grab ( QGraphicsItem only). |
QEvent::UngrabMouse
|
187
|
项丢失鼠标抓取 ( QGraphicsItem , QQuickItem ). |
QEvent::UpdateLater
|
78
|
Widget 应被队列以在稍后重新描绘。 |
QEvent::UpdateRequest
|
77
|
Widget 应被重新描绘。 |
QEvent::WhatsThis
|
111
|
The widget should reveal "What's This?" help ( QHelpEvent ). |
QEvent::WhatsThisClicked
|
118
|
A link in a widget's "What's This?" help was clicked. |
QEvent::Wheel
|
31
|
鼠标滚轮卷动 ( QWheelEvent ). |
QEvent::WinEventAct
|
132
|
发生特定窗口激活事件。 |
QEvent::WindowActivate
|
24
|
窗口被激活。 |
QEvent::WindowBlocked
|
103
|
窗口被模态对话框阻塞。 |
QEvent::WindowDeactivate
|
25
|
窗口被取消激活。 |
QEvent::WindowIconChange
|
34
|
窗口的图标已改变。 |
QEvent::WindowStateChange
|
105
|
窗口状态 (minimized, maximized or full-screen) has changed ( QWindowStateChangeEvent ). |
QEvent::WindowTitleChange
|
33
|
窗口标题已改变。 |
QEvent::WindowUnblocked
|
104
|
The window is unblocked after a modal dialog exited. |
QEvent::WinIdChange
|
203
|
The window system identifer for this native widget has changed. |
QEvent::ZOrderChange
|
126
|
The widget's z-order has changed. This event is never sent to top level windows. |
用户事件应具有的值,介于
User
and
MaxUser
:
常量 | 值 | 描述 |
---|---|---|
QEvent::User
|
1000
|
User-defined event. |
QEvent::MaxUser
|
65535
|
Last user event ID. |
For convenience, you can use the registerEventType () function to register and reserve a custom event type for your application. Doing so will allow you to avoid accidentally re-using a custom event type already in use elsewhere in your application.
事件对象的接受标志
Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget. By default, isAccepted() is set to true, but don't rely on this as subclasses may choose to clear it in their constructor.
为方便起见,接受标志还可以被设置采用 accept (),而清零采用 ignore ().
访问函数:
bool | isAccepted () const |
void | setAccepted (bool accepted ) |
构造事件对象,根据类型 type .
[virtual]
QEvent::
~QEvent
()
销毁事件。若它被 posted ,它将被移除 (从要被张贴的事件列表)。
设置事件对象的接受标志,相当于调用 setAccepted (true).
Setting the accept parameter indicates that the event receiver wants the event. Unwanted events might be propagated to the parent widget.
另请参阅 ignore ().
清零事件对象的接受标志参数,相当于调用 setAccepted (false).
Clearing the accept parameter indicates that the event receiver does not want the event. Unwanted events might be propagated to the parent widget.
另请参阅 accept ().
[static]
int
QEvent::
registerEventType
(
int
hint
= -1)
Registers and returns a custom event type. The hint provided will be used if it is available, otherwise it will return a value between QEvent::User and QEvent::MaxUser that has not yet been registered. The hint is ignored if its value is not between QEvent::User and QEvent::MaxUser .
Returns -1 if all available values are already taken or the program is shutting down.
注意: 此函数是 thread-safe .
This function was introduced in Qt 4.4.
返回
true
若事件发源于应用程序外 (系统事件);否则返回
false
.
此函数的返回值未定义,对于描绘事件。
返回事件类型。