内容表

上一话题

QElapsedTimer

下一话题

QEventLoop

QEvent

QEvent class is the base class of all event classes. Event objects contain event parameters. 更多

Inheritance diagram of PySide2.QtCore.QEvent

继承者: QChildEvent , QDynamicPropertyChangeEvent , QTimerEvent , QStateMachine.SignalEvent , QStateMachine.WrappedEvent , QActionEvent , QCloseEvent , QContextMenuEvent , QDragEnterEvent , QDragLeaveEvent , QDragMoveEvent , QDropEvent , QEnterEvent , QExposeEvent , QFileOpenEvent , QFocusEvent , QHelpEvent , QHideEvent , QHoverEvent , QIconDragEvent , QInputEvent , QInputMethodEvent , QInputMethodQueryEvent , QKeyEvent , QMouseEvent , QMoveEvent , QNativeGestureEvent , QPaintEvent , QResizeEvent , QScrollEvent , QScrollPrepareEvent , QShortcutEvent , QShowEvent , QStatusTipEvent , QTabletEvent , QToolBarChangeEvent , QTouchEvent , QWhatsThisClickedEvent , QWheelEvent , QWindowStateChangeEvent , QGestureEvent , QGraphicsSceneContextMenuEvent , QGraphicsSceneDragDropEvent , QGraphicsSceneEvent , QGraphicsSceneHelpEvent , QGraphicsSceneHoverEvent , QGraphicsSceneMouseEvent , QGraphicsSceneMoveEvent , QGraphicsSceneResizeEvent , QGraphicsSceneWheelEvent

概要

函数

静态函数

详细描述

Qt’s main event loop ( exec() ) fetches native window system events from the event queue, translates them into QEvents, and sends the translated events to QObject s.

通常,事件来自底层窗口系统 ( spontaneous() 返回 true ),但也可能手动发送事件使用 sendEvent() and postEvent() ( spontaneous() 返回 false ).

QObjects 接收事件通过让其 event() function called. The function can be reimplemented in subclasses to customize event handling and add additional event types; event() is a notable example. By default, events are dispatched to event handlers like timerEvent() and mouseMoveEvent() . installEventFilter() allows an object to intercept events destined for another object.

The basic QEvent contains only an event type parameter and an “accept” flag. The accept flag set with accept() , and cleared with ignore() . It is set by default, but don’t rely on this as subclasses may choose to clear it in their constructor.

子类化的 QEvent contain additional parameters that describe the particular event.

class QEvent ( type )

QEvent(other)

param type

Type

param other

QEvent

构造事件对象,根据类型 type .

构造事件对象,根据类型 type .

PySide2.QtCore.QEvent. Type

此枚举类型定义 Qt 中的有效事件类型。事件类型和用于每个类型的专用类如下:

常量

描述

QEvent.None

不是事件。

QEvent.ActionAdded

新的动作已被添加 ( QActionEvent ).

QEvent.ActionChanged

动作已被改变 ( QActionEvent ).

QEvent.ActionRemoved

动作已被移除 ( QActionEvent ).

QEvent.ActivationChange

A widget’s top-level window activation state has changed.

QEvent.ApplicationActivate

This enum has been deprecated. Use instead.

QEvent.ApplicationActivated

This enum has been deprecated. Use instead.

QEvent.ApplicationDeactivate

This enum has been deprecated. Use instead.

QEvent.ApplicationFontChange

默认应用程序字体已改变。

QEvent.ApplicationLayoutDirectionChange

默认的应用程序布局方向已改变。

QEvent.ApplicationPaletteChange

默认的应用程序调色板已改变。

QEvent.ApplicationStateChange

应用程序的状态已改变。

QEvent.ApplicationWindowIconChange

The application’s icon has changed.

QEvent.ChildAdded

对象获取子级 ( QChildEvent ).

QEvent.ChildPolished

Widget 子级被抛光 ( QChildEvent ).

QEvent.ChildRemoved

对象失去子级 ( QChildEvent ).

QEvent.Clipboard

剪贴板内容已改变。

QEvent.Close

Widget 被关闭 ( QCloseEvent ).

QEvent.CloseSoftwareInputPanel

Widget 想要关闭 SIP (软件输入面板)。

QEvent.ContentsRectChange

The margins of the widget’s content rect changed.

QEvent.ContextMenu

上下文弹出菜单 ( QContextMenuEvent ).

QEvent.CursorChange

The widget’s cursor has changed.

QEvent.DeferredDelete

对象将被删除,在它已被清理之后 ( QDeferredDeleteEvent )

QEvent.DragEnter

光标进入 Widget 在拖放操作期间 ( QDragEnterEvent ).

QEvent.DragLeave

光标离开 Widget 在拖放操作期间 ( QDragLeaveEvent ).

QEvent.DragMove

拖放操作正在进行中 ( QDragMoveEvent ).

QEvent.Drop

拖放操作完成 ( QDropEvent ).

QEvent.DynamicPropertyChange

添加、更改或从对象移除动态特性。

QEvent.EnabledChange

Widget’s enabled state has changed.

QEvent.Enter

Mouse enters widget’s boundaries ( QEnterEvent ).

QEvent.EnterEditFocus

编辑器 Widget 获得编辑聚焦。 QT_KEYPAD_NAVIGATION 必须有定义。

QEvent.EnterWhatsThisMode

Send to toplevel widgets when the application enters “What’s This?” mode.

QEvent.Expose

发送给窗口,当其屏幕内容无效且需要从后备存储刷新时。

QEvent.FileOpen

文件打开请求 ( QFileOpenEvent ).

QEvent.FocusIn

Widget 或窗口获得键盘聚焦 ( QFocusEvent ).

QEvent.FocusOut

Widget 或窗口丢失键盘聚焦 ( QFocusEvent ).

QEvent.FocusAboutToChange

Widget 或窗口聚焦即将改变 ( QFocusEvent )

QEvent.FontChange

Widget’s font has changed.

QEvent.Gesture

手势被触发 ( QGestureEvent ).

QEvent.GestureOverride

手势覆盖被触发 ( QGestureEvent ).

QEvent.GrabKeyboard

项获得键盘抓取 ( QGraphicsItem 仅)。

QEvent.GrabMouse

项获得鼠标抓取 ( QGraphicsItem 仅)。

QEvent.GraphicsSceneContextMenu

Context popup menu over a graphics scene ( QGraphicsSceneContextMenuEvent ).

QEvent.GraphicsSceneDragEnter

The cursor enters a graphics scene during a drag and drop operation ( QGraphicsSceneDragDropEvent ).

QEvent.GraphicsSceneDragLeave

The cursor leaves a graphics scene during a drag and drop operation ( QGraphicsSceneDragDropEvent ).

QEvent.GraphicsSceneDragMove

A drag and drop operation is in progress over a scene ( QGraphicsSceneDragDropEvent ).

QEvent.GraphicsSceneDrop

A drag and drop operation is completed over a scene ( QGraphicsSceneDragDropEvent ).

QEvent.GraphicsSceneHelp

用户请求用于图形场景的帮助 ( QHelpEvent ).

QEvent.GraphicsSceneHoverEnter

The mouse cursor enters a hover item in a graphics scene ( QGraphicsSceneHoverEvent ).

QEvent.GraphicsSceneHoverLeave

The mouse cursor leaves a hover item in a graphics scene ( QGraphicsSceneHoverEvent ).

QEvent.GraphicsSceneHoverMove

The mouse cursor moves inside a hover item in a graphics scene ( QGraphicsSceneHoverEvent ).

QEvent.GraphicsSceneMouseDoubleClick

Mouse press again (double click) in a graphics scene ( QGraphicsSceneMouseEvent ).

QEvent.GraphicsSceneMouseMove

Move mouse in a graphics scene ( QGraphicsSceneMouseEvent ).

QEvent.GraphicsSceneMousePress

Mouse press in a graphics scene ( QGraphicsSceneMouseEvent ).

QEvent.GraphicsSceneMouseRelease

Mouse release in a graphics scene ( QGraphicsSceneMouseEvent ).

QEvent.GraphicsSceneMove

Widget 被移除 ( QGraphicsSceneMoveEvent ).

QEvent.GraphicsSceneResize

Widget 被重置尺寸 ( QGraphicsSceneResizeEvent ).

QEvent.GraphicsSceneWheel

鼠标滚轮在图形场景中卷动 ( QGraphicsSceneWheelEvent ).

QEvent.Hide

Widget 被隐藏 ( QHideEvent ).

QEvent.HideToParent

子级 Widget 已隐藏。

QEvent.HoverEnter

鼠标光标进入悬停 Widget ( QHoverEvent ).

QEvent.HoverLeave

鼠标光标离开悬停 Widget ( QHoverEvent ).

QEvent.HoverMove

鼠标光标在悬停 Widget 内移动 ( QHoverEvent ).

QEvent.IconDrag

The main icon of a window has been dragged away ( QIconDragEvent ).

QEvent.IconTextChange

Widget’s icon text has been changed. (Deprecated)

QEvent.InputMethod

An input method is being used ( QInputMethodEvent ).

QEvent.InputMethodQuery

A input method query event ( QInputMethodQueryEvent )

QEvent.KeyboardLayoutChange

键盘布局已改变。

QEvent.KeyPress

键按下 ( QKeyEvent ).

QEvent.KeyRelease

键释放 ( QKeyEvent ).

QEvent.LanguageChange

应用程序翻译已改变。

QEvent.LayoutDirectionChange

布局的方向已改变。

QEvent.LayoutRequest

Widget 布局需要重做。

QEvent.Leave

Mouse leaves widget’s boundaries.

QEvent.LeaveEditFocus

An editor widget loses focus for editing. QT_KEYPAD_NAVIGATION must be defined.

QEvent.LeaveWhatsThisMode

Send to toplevel widgets when the application leaves “What’s This?” mode.

QEvent.LocaleChange

系统区域设置已改变。

QEvent.NonClientAreaMouseButtonDblClick

A mouse double click occurred outside the client area ( QMouseEvent ).

QEvent.NonClientAreaMouseButtonPress

A mouse button press occurred outside the client area ( QMouseEvent ).

QEvent.NonClientAreaMouseButtonRelease

A mouse button release occurred outside the client area ( QMouseEvent ).

QEvent.NonClientAreaMouseMove

A mouse move occurred outside the client area ( QMouseEvent ).

QEvent.MacSizeChange

The user changed his widget sizes (macOS only).

QEvent.MetaCall

An asynchronous method invocation via invokeMethod() .

QEvent.ModifiedChange

Widgets modification state has been changed.

QEvent.MouseButtonDblClick

再次按下鼠标 ( QMouseEvent ).

QEvent.MouseButtonPress

鼠标按下 ( QMouseEvent ).

QEvent.MouseButtonRelease

鼠标释放 ( QMouseEvent ).

QEvent.MouseMove

鼠标移动 ( QMouseEvent ).

QEvent.MouseTrackingChange

鼠标跟踪状态已改变。

QEvent.Move

Widget’s position changed ( QMoveEvent ).

QEvent.NativeGesture

The system has detected a gesture ( QNativeGestureEvent ).

QEvent.OrientationChange

The screens orientation has changes ( QScreenOrientationChangeEvent ).

QEvent.Paint

必要的屏幕更新 ( QPaintEvent ).

QEvent.PaletteChange

Palette of the widget changed.

QEvent.ParentAboutToChange

The widget parent is about to change.

QEvent.ParentChange

The widget parent has changed.

QEvent.PlatformPanel

A platform specific panel has been requested.

QEvent.PlatformSurface

本机平台表面已被创建或即将被销毁 ( QPlatformSurfaceEvent ).

QEvent.Polish

Widget 被抛光。

QEvent.PolishRequest

Widget 应该被抛光。

QEvent.QueryWhatsThis

The widget should accept the event if it has “What’s This?” help ( QHelpEvent ).

QEvent.ReadOnlyChange

Widget’s read-only state has changed (since Qt 5.4).

QEvent.RequestSoftwareInputPanel

A widget wants to open a software input panel (SIP).

QEvent.Resize

Widget’s size changed ( QResizeEvent ).

QEvent.ScrollPrepare

The object needs to fill in its geometry information ( QScrollPrepareEvent ).

QEvent.Scroll

The object needs to scroll to the supplied position ( QScrollEvent ).

QEvent.Shortcut

Key press in child for shortcut key handling ( QShortcutEvent ).

QEvent.ShortcutOverride

在子级中按下键,为覆盖快捷键处理 ( QKeyEvent )。当快捷键即将被触发时, ShortcutOverride 被发送给活动窗口。这允许客户端 (如 Widget) 通过接受事件,以信号它们自己将处理快捷键。若快捷键覆盖被接受,事件作为常规键按下被交付给聚焦 Widget。否则,它触发快捷键动作,若存在的话。

QEvent.Show

Widget 被展示在屏幕上 ( QShowEvent ).

QEvent.ShowToParent

子级 Widget 已被展示。

QEvent.SockAct

套接字被激活,用于实现 QSocketNotifier .

QEvent.StateMachineSignal

交付给状态机的信号 ( SignalEvent ).

QEvent.StateMachineWrapped

事件是包裹器,即:包含另一事件 ( WrappedEvent ).

QEvent.StatusTip

A status tip is requested ( QStatusTipEvent ).

QEvent.StyleChange

Widget’s style has been changed.

QEvent.TabletMove

Wacom 平板移动 ( QTabletEvent ).

QEvent.TabletPress

Wacom 数位板按下 ( QTabletEvent ).

QEvent.TabletRelease

Wacom 数位板释放 ( QTabletEvent ).

QEvent.TabletEnterProximity

Wacom tablet enter proximity event ( QTabletEvent ), sent to QApplication .

QEvent.TabletLeaveProximity

Wacom tablet leave proximity event ( QTabletEvent ), sent to QApplication .

QEvent.TabletTrackingChange

The Wacom tablet tracking state has changed (since Qt 5.9).

QEvent.ThreadChange

The object is moved to another thread. This is the last event sent to this object in the previous thread. See moveToThread() .

QEvent.Timer

常规计时器事件 ( QTimerEvent ).

QEvent.ToolBarChange

The toolbar button is toggled on macOS.

QEvent.ToolTip

请求工具提示 ( QHelpEvent ).

QEvent.ToolTipChange

The widget’s tooltip has changed.

QEvent.TouchBegin

Beginning of a sequence of touch-screen or track-pad events ( QTouchEvent ).

QEvent.TouchCancel

取消触摸事件序列 ( QTouchEvent ).

QEvent.TouchEnd

触摸事件序列结束 ( QTouchEvent ).

QEvent.TouchUpdate

触摸屏事件 ( QTouchEvent ).

QEvent.UngrabKeyboard

项丢失键盘抓取 ( QGraphicsItem 仅)。

QEvent.UngrabMouse

项丢失鼠标抓取 ( QGraphicsItem , QQuickItem ).

QEvent.UpdateLater

Widget 应被队列以在稍后重新描绘。

QEvent.UpdateRequest

Widget 应被重新描绘。

QEvent.WhatsThis

The widget should reveal “What’s This?” help ( QHelpEvent ).

QEvent.WhatsThisClicked

A link in a widget’s “What’s This?” help was clicked.

QEvent.Wheel

鼠标滚轮卷动 ( QWheelEvent ).

QEvent.WinEventAct

发生特定窗口激活事件。

QEvent.WindowActivate

窗口被激活。

QEvent.WindowBlocked

窗口被模态对话框阻塞。

QEvent.WindowDeactivate

窗口被取消激活。

QEvent.WindowIconChange

The window’s icon has changed.

QEvent.WindowStateChange

window's state (最小化、最大化或全屏) 已改变 ( QWindowStateChangeEvent ).

QEvent.WindowTitleChange

窗口标题已改变。

QEvent.WindowUnblocked

窗口被解除阻塞在退出模态对话框后。

QEvent.WinIdChange

此本机 Widget 窗口系统标识符已改变。

QEvent.ZOrderChange

The widget’s z-order has changed. This event is never sent to top level windows.

用户事件应具有的值,介于 User and MaxUser :

常量

描述

QEvent.User

用户定义事件。

QEvent.MaxUser

上次用户事件 ID。

为方便起见,可以使用 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.

PySide2.QtCore.QEvent. accept ( )

设置事件对象的接受标志,相当于调用 setAccepted (true)。

设置接受参数指示事件接收器想要事件。不想要事件可能被传播给父级 Widget。

另请参阅

ignore()

PySide2.QtCore.QEvent. ignore ( )

清零事件对象的接受标志参数,相当于调用 setAccepted (false).

清零接受参数指示事件接收器不想要事件。不想要事件被传播给父级 Widget。

另请参阅

accept()

PySide2.QtCore.QEvent. isAccepted ( )
返回类型

bool

static PySide2.QtCore.QEvent. registerEventType ( [ hint=-1 ] )
参数

hint int

返回类型

int

注册并返回自定义事件类型。 hint 提供将被使用若可用,否则返回值介于 User and MaxUser 尚未被注册。 hint 被忽略若其值不介于 User and MaxUser .

返回 -1 若已获取所有可用值或程序正关闭。

PySide2.QtCore.QEvent. setAccepted ( accepted )
参数

accepted bool

另请参阅

isAccepted()

PySide2.QtCore.QEvent. spontaneous ( )
返回类型

bool

返回 true 若事件发源于应用程序外 (系统事件);否则返回 false .

此函数的返回值未定义,对于描绘事件。

PySide2.QtCore.QEvent. type ( )
返回类型

Type

返回事件类型。