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