From 93efbb06c4ec4234fec26caaa6853fcf1aaf5df5 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 30 May 2026 10:20:47 +0200 Subject: [PATCH] =?UTF-8?q?Refresca=20b=C3=A9=20el=20canvi=20de=20tema=20e?= =?UTF-8?q?n=20calent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setPalette no repolia els widgets ja creats: els stylesheets amb palette(...) (pills) no es reresolien i la consola de log no repintava el fons. apply_theme ara fa unpolish→polish→update a tots els widgets, i en canviar de tema es reconstrueixen les files perquè els pills agafin la paleta nova. Co-Authored-By: Claude Opus 4.8 (1M context) --- jlauncher/ui/main_window.py | 4 ++++ jlauncher/ui/theme.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/jlauncher/ui/main_window.py b/jlauncher/ui/main_window.py index f90049f..a39a4d1 100644 --- a/jlauncher/ui/main_window.py +++ b/jlauncher/ui/main_window.py @@ -175,6 +175,10 @@ class MainWindow(QMainWindow): app = QApplication.instance() if app is not None: theme.apply_theme(app, mode) + # Reconstruir las filas: los pills usan `palette(...)` en su stylesheet, que + # Qt cachea; recrearlos los re-resuelve contra la paleta ya aplicada. + for row in self.rows.values(): + row.refresh() def _configure_token(self) -> None: token, ok = QInputDialog.getText( diff --git a/jlauncher/ui/theme.py b/jlauncher/ui/theme.py index dc287fa..742fafb 100644 --- a/jlauncher/ui/theme.py +++ b/jlauncher/ui/theme.py @@ -120,6 +120,20 @@ def resolve_is_dark(app: QApplication, mode: str) -> bool: return system_is_dark(app) # THEME_SYSTEM (o valor desconocido) +def _repolish_all(app: QApplication) -> None: + """Re-poliza todos los widgets para que adopten la nueva paleta en caliente. + + ``setPalette`` por sí solo no repinta los widgets ya creados: los que tienen + stylesheet (pills) no re-resuelven ``palette(...)`` y algunos fondos base (la + consola de log) no se redibujan. unpolish→polish→update fuerza ese refresco. + """ + for widget in app.allWidgets(): + style = widget.style() + style.unpolish(widget) + style.polish(widget) + widget.update() + + def apply_theme(app: QApplication, mode: str = THEME_SYSTEM) -> None: """Aplica estilo Fusion + paleta clara/oscura según el modo elegido.""" app.setStyle("Fusion") @@ -127,6 +141,7 @@ def apply_theme(app: QApplication, mode: str = THEME_SYSTEM) -> None: app.setPalette(_dark_palette()) else: app.setPalette(app.style().standardPalette()) + _repolish_all(app) def watch_system_theme(app: QApplication, should_follow: Callable[[], bool]) -> None: