QCloseEvent Class
QCloseEvent 类包含描述关闭事件的参数。更多
头文件: | #include <QCloseEvent> |
CMake.QCloseEvent | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QEvent |
- 所有成员(包括继承成员)的列表
- QCloseEvent 属于事件类。
公共函数
详细说明
关闭事件会发送到用户希望关闭的部件,通常是通过从窗口菜单中选择 "关闭",或点击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().
© 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.