QCloseEvent Class
QCloseEvent 类包含描述关闭事件的参数。更多内容...
| 头文件: | #include <QCloseEvent> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
| 继承自: | QEvent |
- 所有成员列表(包括继承的成员)
- QCloseEvent 属于事件类。
公共函数
受保护函数
| QCloseEvent(QCloseEvent &&) | |
| QCloseEvent & | operator=(QCloseEvent &&) |
| QCloseEvent & | operator=(const QCloseEvent &other) |
详细说明
关闭事件会发送给用户想要关闭的小部件,通常是通过从窗口菜单中选择“关闭”,或单击X 标题栏按钮来实现的。当您调用QWidget::close()以编程方式关闭小部件时,也会发送这些事件。
关闭事件包含一个标志,用于指示接收方是否希望关闭该小部件。 当小部件接受关闭事件时,它会被隐藏(如果它是通过Qt::WA_DeleteOnClose 标志创建的,则会被销毁)。如果它拒绝接受关闭事件,则不会发生任何变化。(在X11环境下,窗口管理器可能会强制关闭该窗口;但在本文撰写之时,我们尚未发现有任何窗口管理器会这样做。)
事件处理函数 `QWidget::closeEvent()` 用于接收关闭事件。该事件处理函数的默认实现会接受关闭事件。若您不希望小部件被隐藏,或者需要进行特殊处理,应重写该事件处理函数,并使用 `ignore()` 拒绝该事件。
若希望小部件在关闭时被删除,请使用Qt::WA_DeleteOnClose 标志创建它。这对于多窗口应用程序中的独立顶级窗口非常有用。
QObject当小部件被删除时,会发出destroyed() 信号。
如果最后一个顶级窗口被关闭,则会发出QGuiApplication::lastWindowClosed() 信号。
如果事件的接收者已同意关闭该小部件,则isAccepted()函数返回true ;调用accept()以同意关闭该小部件,如果该事件的接收者不希望关闭该小部件,则调用ignore()。
另请参阅 QWidget::close()、QWidget::hide()、QObject::destroyed()、QCoreApplication::exec()、QCoreApplication::quit() 以及QGuiApplication::lastWindowClosed()。
成员函数文档
QCloseEvent::QCloseEvent()
构建一个关闭事件对象。
另请参阅 accept()。
[protected delete] QCloseEvent::QCloseEvent(QCloseEvent &&)
通过移动构造生成一个QCloseEvent 实例。该函数已被删除。
[protected delete] QCloseEvent &QCloseEvent::operator=(QCloseEvent &&)
将other 按移动赋值方式赋给此QCloseEvent 实例。该函数已被删除。
[noexcept protected default] QCloseEvent &QCloseEvent::operator=(const QCloseEvent &other)
将other 复制并赋值给该QCloseEvent 实例。
© 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.