QEventTransition Class

QEventTransition 类为 Qt 事件提供QObject 特有的过渡。更多

Header: #include <QEventTransition>
CMake: find_package(Qt6 REQUIRED COMPONENTS StateMachine)
target_link_libraries(mytarget PRIVATE Qt6::StateMachine)
qmake: QT += statemachine
继承: QAbstractTransition
继承于

QKeyEventTransitionQMouseEventTransition

属性

公共函数

QEventTransition(QState *sourceState = nullptr)
QEventTransition(QObject *object, QEvent::Type type, QState *sourceState = nullptr)
virtual ~QEventTransition()
QBindable<QObject *> bindableEventSource()
QBindable<QEvent::Type> bindableEventType()
QObject *eventSource() const
QEvent::Type eventType() const
void setEventSource(QObject *object)
void setEventType(QEvent::Type type)

重新实现的受保护函数

virtual bool event(QEvent *e) override
virtual bool eventTest(QEvent *event) override
virtual void onTransition(QEvent *event) override

详细说明

QEventTransition 对象将一个事件绑定到一个特定的QObject 。QEventTransition 是Qt State Machine Framework 的一部分。

示例

QPushButton *button = ...;
QState *s1 = ...;
QState *s2 = ...;
// If in s1 and the button receives an Enter event, transition to s2
QEventTransition *enterTransition = new QEventTransition(button, QEvent::Enter);
enterTransition->setTargetState(s2);
s1->addTransition(enterTransition);
// If in s2 and the button receives an Exit event, transition back to s1
QEventTransition *leaveTransition = new QEventTransition(button, QEvent::Leave);
leaveTransition->setTargetState(s1);
s2->addTransition(leaveTransition);

子类化

在重新实现eventTest() 函数时,您应首先调用基本实现,以验证该事件是否为QStateMachine::WrappedEvent 的适当对象和事件类型。然后,您可以将事件转换为QStateMachine::WrappedEvent ,并通过调用QStateMachine::WrappedEvent::event() 获取原始事件,然后对该对象执行附加检查。

另请参阅 QState::addTransition()。

属性文档

[bindable] eventSource : QObject*

注意: 该属性支持QProperty 绑定。

此属性保存与此事件过渡相关联的事件源

[bindable] eventType : QEvent::Type

注意: 此属性支持QProperty 绑定。

此属性保存与此事件转换相关联的事件类型

成员函数文档

QEventTransition::QEventTransition(QState *sourceState = nullptr)

用给定的sourceState 构建一个新的 QEventTransition 对象。

QEventTransition::QEventTransition(QObject *object, QEvent::Type type, QState *sourceState = nullptr)

构造一个新的 QEventTransition 对象,该对象与给定type 的给定object 的给定sourceState 的事件相关联。

[virtual noexcept] QEventTransition::~QEventTransition()

销毁QObject 事件转换。

[override virtual protected] bool QEventTransition::event(QEvent *e)

重实现:QAbstractTransition::event(QEvent *e)。

QObject *QEventTransition::eventSource() const

返回与此事件转换相关的事件源。

注: 属性 eventSource 的获取函数。

另请参阅 setEventSource().

[override virtual protected] bool QEventTransition::eventTest(QEvent *event)

重实现:QAbstractTransition::eventTest(QEvent *event).

QEvent::Type QEventTransition::eventType() const

返回与此事件转换相关联的事件类型。

注: 属性 eventType 的获取函数。

另请参阅 setEventType().

[override virtual protected] void QEventTransition::onTransition(QEvent *event)

重实现:QAbstractTransition::onTransition(QEvent *event).

void QEventTransition::setEventSource(QObject *object)

将与此事件转换相关联的事件源设置为给定的object

注: 属性eventSource 的设置函数。

另请参阅 eventSource() 。

void QEventTransition::setEventType(QEvent::Type type)

设置与此事件转换相关联的事件type

注: 属性eventType 的设置函数。

另请参阅 eventType().

© 2025 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.