From 2acdc8c30a0e46a49397ce39d4a38cd393fe7590 Mon Sep 17 00:00:00 2001 From: Evgeny Kulikov <248055+beyondcompute@users.noreply.github.com> Date: Sun, 27 Apr 2025 11:25:20 +0300 Subject: [PATCH] Close only "child" window (e.g. Preview) inside Browser on Cmd+W (#3913) Currently, if a user tries to close Preview which was opened inside Browse, the "parent" Browse window itself gets closed Co-authored-by: beyondcompute --- qt/aqt/browser/browser.py | 13 +++++++++++++ qt/aqt/forms/browser.ui | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index 21ca886de..bf953871a 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -280,6 +280,19 @@ class Browser(QMainWindow): if note_type_id := self.get_active_note_type_id(): add_cards.set_note_type(note_type_id) + # If in the Browser we open Preview and press Ctrl+W there, + # both Preview and Browser windows get closed by Qt out of the box. + # We circumvent that behavior by only closing the currently active window + def _handle_close(self): + active_window = QApplication.activeWindow() + if active_window and active_window != self: + if isinstance(active_window, QDialog): + active_window.reject() + else: + active_window.close() + else: + self.close() + def setupMenus(self) -> None: # actions f = self.form diff --git a/qt/aqt/forms/browser.ui b/qt/aqt/forms/browser.ui index f50ad25cd..765a71025 100644 --- a/qt/aqt/forms/browser.ui +++ b/qt/aqt/forms/browser.ui @@ -792,7 +792,7 @@ actionClose triggered() Dialog - close() + _handle_close() -1