From 732f104c5cfa98b813a23b0c68af4702157821af Mon Sep 17 00:00:00 2001 From: KenanZhu <3471685733@qq.com> Date: Sat, 30 May 2026 21:37:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(gui):=20=E9=87=8D=E5=91=BD=E5=90=8D=20?= =?UTF-8?q?=5FapplyThemeByName=20=E2=86=92=20=5FapplyCustomTheme=EF=BC=8C?= =?UTF-8?q?=5FclearQss=20=E2=86=92=20=5FclearCustomTheme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _clearCustomTheme(theme) 清除 QSS 后切换到指定默认主题 - _applyCustomTheme(name, fallback_theme) 应用自定义主题,失败时回退到 fallback_theme - saveAndApply 调用处传入当前 radio 主题作为 fallback --- src/gui/ALSettingsWidget.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gui/ALSettingsWidget.py b/src/gui/ALSettingsWidget.py index 5ca3e91..2ce9db2 100644 --- a/src/gui/ALSettingsWidget.py +++ b/src/gui/ALSettingsWidget.py @@ -50,24 +50,27 @@ def _setActiveStyleName( global _active_style_name _active_style_name = name -def _clearQss( +def _clearCustomTheme( + theme: str ): app : QApplication | None = QApplication.instance() if app: app.setStyleSheet("") + _applyTheme(theme) -def _applyThemeByName( - name: str +def _applyCustomTheme( + name: str, + fallback_theme: str = "system" ): if not name: - _clearQss() + _clearCustomTheme(fallback_theme) return try: themeInstance().applyTheme(name) except Exception: - _clearQss() + _clearCustomTheme(fallback_theme) def _applyTheme( theme: str @@ -274,7 +277,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget): self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.THEME, theme) self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.STYLE, style) self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.CUSTOM_THEME, custom_theme) - _applyThemeByName(custom_theme) + _applyCustomTheme(custom_theme, theme) self._syncRadioFromNeedTheme(custom_theme) theme, _, _ = self.collectSettings() _applyTheme(theme)