QSystemTrayIcon example: ignore non-spontaneous QCloseEvent

Apparently this code is needed on other platforms now, not only macOS.

Pick-to: 6.2
Fixes: QTBUG-98504
Change-Id: Ie0a7e38609e8fc8c11915784dd3652a3517bb639
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
Shawn Rutledge 2021-11-22 17:39:20 +01:00
parent 6598a26a13
commit 46cadf7b48
2 changed files with 5 additions and 8 deletions

View File

@ -173,11 +173,11 @@
We have reimplemented the QWidget::closeEvent() event handler to
receive widget close events, showing the above message to the
users when they are closing the editor window. On \macos we need to
users when they are closing the editor window. We need to
avoid showing the message and accepting the close event when the
user really intends to quit the application, that is, when the
user has triggered "Quit" in the menu bar or pressed the Command+Q
shortcut.
user really intends to quit the application: that is, when the
user has triggered "Quit" in the menu bar, or in the tray icon's
context menu, or pressed Command+Q shortcut on \macOS.
In addition to the functions and slots discussed above, we have
also implemented several convenience functions to simplify the

View File

@ -111,11 +111,8 @@ void Window::setVisible(bool visible)
//! [2]
void Window::closeEvent(QCloseEvent *event)
{
#ifdef Q_OS_MACOS
if (!event->spontaneous() || !isVisible()) {
if (!event->spontaneous() || !isVisible())
return;
}
#endif
if (trayIcon->isVisible()) {
QMessageBox::information(this, tr("Systray"),
tr("The program will keep running in the "