From d0840d68fbe5584988de544fd302afc3e8a054ab Mon Sep 17 00:00:00 2001 From: liujinchang Date: Thu, 29 Oct 2026 01:59:01 +0800 Subject: [PATCH] fix: change close dialog default to exit and ignore close event only on minimise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: closeEvent unconditionally called event->ignore() after showCloseDialog(), preventing Qt from closing the window and exiting the process regardless of user choice; default option was "Minimise" which kept the process alive in background 2. Fix: change showCloseDialog() to return bool (true=minimise path, false=exit/cancel), only call event->ignore() when it returns true; change default checkbox from "Minimise to system tray" to "Exit" 3. Impact: closing window now defaults to exit; cancelling the dialog allows normal window close; minimise-to-tray remains available as user-selected option; existing users with saved "Minimise" unaffected Log: close window now defaults to exit instead of minimise to tray Influence: 1. Test closing window with default "Exit" option - process should exit 2. Test selecting "Minimise to system tray" - process stays in tray 3. Test cancelling dialog - window closes and process exits 4. Test "don't ask again" with both options - saved behaviour persists 5. Verify existing users with saved "Minimise" still get minimise behaviour fix: 关闭对话框默认选项改为退出且仅在最小化时忽略关闭事件 1. 根因:closeEvent 在 showCloseDialog() 后无条件调用 event->ignore(), 阻止 Qt 关闭窗口和退出进程;默认选项为"最小化"导致进程驻留后台 2. 方案:将 showCloseDialog() 改为返回 bool(true=最小化路径, false=退出/取消),仅在返回 true 时调用 event->ignore(); 将默认勾选项从"最小化到系统托盘"改为"退出" 3. 影响:关闭窗口默认退出进程;取消对话框时窗口正常关闭; 最小化到托盘仍作为用户可选选项保留;已保存"最小化"的用户不受影响 Log: 关闭窗口默认改为退出而非最小化到托盘 Influence: 1. 测试默认"退出"选项关闭窗口 - 进程应退出 2. 测试选择"最小化到系统托盘" - 进程保留在托盘 3. 测试取消对话框 - 窗口关闭且进程退出 4. 测试"不再询问"两种选项 - 保存的行为持续生效 5. 验证已保存"最小化"的用户仍保持最小化行为 Bug: #274633 --- .../cooperation/core/gui/mainwindow.cpp | 23 ++++++++++++------- src/plugins/cooperation/core/gui/mainwindow.h | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/plugins/cooperation/core/gui/mainwindow.cpp b/src/plugins/cooperation/core/gui/mainwindow.cpp index cb6fbf6cb..8a2c2d456 100644 --- a/src/plugins/cooperation/core/gui/mainwindow.cpp +++ b/src/plugins/cooperation/core/gui/mainwindow.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -179,27 +179,29 @@ void MainWindow::closeEvent(QCloseEvent *event) if (qApp->property("onlyTransfer").toBool()) QApplication::quit(); - showCloseDialog(); - event->ignore(); + if (showCloseDialog()) + event->ignore(); } -void MainWindow::showCloseDialog() +bool MainWindow::showCloseDialog() { QString option = CooperationUtil::closeOption(); if (option == "Minimise") { minimizedAPP(); - return; + return true; } - if (option == "Exit") + if (option == "Exit") { QApplication::quit(); + return false; + } CooperationDialog dlg(qApp->activeWindow()); dlg.setFixedSize(360, 260); QVBoxLayout *layout = new QVBoxLayout(); QCheckBox *op1 = new QCheckBox(tr("Minimise to system tray")); - op1->setChecked(true); QCheckBox *op2 = new QCheckBox(tr("Exit")); + op2->setChecked(true); connect(op1, &QCheckBox::stateChanged, op1, [op2](int state) { op2->setChecked(state != Qt::Checked); @@ -246,10 +248,15 @@ void MainWindow::showCloseDialog() } if (isExit) + { QApplication::quit(); - else + return false; + } else { minimizedAPP(); + return true; + } } + return false; } void MainWindow::minimizedAPP() diff --git a/src/plugins/cooperation/core/gui/mainwindow.h b/src/plugins/cooperation/core/gui/mainwindow.h index 3db555212..e437ed887 100644 --- a/src/plugins/cooperation/core/gui/mainwindow.h +++ b/src/plugins/cooperation/core/gui/mainwindow.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023-2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -30,7 +30,7 @@ class MainWindow : public CooperationMainWindow #endif void closeEvent(QCloseEvent *event) override; - void showCloseDialog(); + bool showCloseDialog(); void minimizedAPP(); public Q_SLOTS: void setFirstTipVisible();