本页内容

QActionEvent Class

QActionEvent 类提供了一种事件,该事件在添加、移除或修改QAction 时触发。更多内容...

头文件: #include <QActionEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承自: QEvent

公共函数

QActionEvent(int type, QAction *action, QAction *before = nullptr)
QAction *action() const
QAction *before() const

受保护函数

QActionEvent(QActionEvent &&)
QActionEvent &operator=(QActionEvent &&)
QActionEvent &operator=(const QActionEvent &other)

详细说明

可以通过调用QWidget::addAction()等方式向控件添加操作。这会生成一个ActionAdded 事件,您可以通过处理该事件来提供自定义行为。例如,QToolBar 重写了QWidget::actionEvent()方法,为这些操作创建QToolButton对象。

另请参阅 QAction 、QWidget::addAction()、QWidget::removeAction() 以及QWidget::actions()。

成员函数文档

QActionEvent::QActionEvent(int type, QAction *action, QAction *before = nullptr)

构建一个操作事件。type 可以是ActionChanged 、ActionAdded 或ActionRemoved 。

action 表示被修改、添加或移除的操作。如果type 为ActionAdded,则该操作将被插入到before 操作之前;如果before 为nullptr ,则该操作将被追加。

[protected delete] QActionEvent::QActionEvent(QActionEvent &&)

通过移动构造一个QActionEvent 的实例。该函数已被删除。

QAction *QActionEvent::action() const

返回被修改、添加或删除的操作。

另请参阅 ` before()`。

QAction *QActionEvent::before() const

如果type() 的返回值为ActionAdded ,则返回应在action() 之前执行的操作。如果该函数返回nullptr ,则该操作应附加到同一控件上已存在的操作之后。

另请参阅 action() 和QWidget::actions()。

[protected delete] QActionEvent &QActionEvent::operator=(QActionEvent &&)

将other 按移动赋值方式赋值给此QActionEvent 实例。该函数已被删除。

[noexcept protected default] QActionEvent &QActionEvent::operator=(const QActionEvent &other)

将 `other ` 复制并赋值给该 `QActionEvent ` 实例。

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