From 401c93836d9bda6db36c64c6c4e06ffe9e33406b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 13 Oct 2026 09:14:56 +0000 Subject: [PATCH] fix(bec_status_box): restyle the QWidget view when the theme changes Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_015TeMnCZ9FjLpwiDkPu6K9j --- .../services/bec_status_box/bec_status_box.py | 10 ++++++++++ tests/unit_tests/test_bec_status_box.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/bec_widgets/widgets/services/bec_status_box/bec_status_box.py b/bec_widgets/widgets/services/bec_status_box/bec_status_box.py index ae8734de..2734c908 100644 --- a/bec_widgets/widgets/services/bec_status_box/bec_status_box.py +++ b/bec_widgets/widgets/services/bec_status_box/bec_status_box.py @@ -271,6 +271,16 @@ class BECStatusBox(BECWidget, CompactPopupWidget): ) self.tooltip = f"{self.model.headline}\n{self.model.detail}".strip() + @SafeSlot(str) + def apply_theme(self, theme: str): + """Restyle the QWidget view after a theme change. The QML view follows the theme itself. + + Args: + theme (str): The name of the new theme. + """ + if isinstance(self.view, StatusBoxWidgetView): + self.view.apply_theme() + def cleanup(self): """Cleanup the BECStatusBox widget.""" self.bec_service_status.cleanup() diff --git a/tests/unit_tests/test_bec_status_box.py b/tests/unit_tests/test_bec_status_box.py index e6e8cd9e..86dcd3d1 100644 --- a/tests/unit_tests/test_bec_status_box.py +++ b/tests/unit_tests/test_bec_status_box.py @@ -257,3 +257,22 @@ def test_build_rows_order_and_groups(): assert [r.group for r in rows] == [CORE_GROUP, CORE_GROUP, OTHER_GROUP, OTHER_GROUP] assert rows[1].tone == "emergency" assert rows[3].status == "NOTCONNECTED" + + +def test_widget_view_follows_theme(qtbot, mocked_client): + from bec_widgets.utils.colors import apply_theme + + box = create_widget( + qtbot, + BECStatusBox, + client=mocked_client, + bec_service_status_mixin=mock.MagicMock(), + view="widgets", + ) + box.update_service_status(*_all_services()) + apply_theme("dark") + dark = box.view.styleSheet() + apply_theme("light") + qtbot.waitUntil(lambda: box.view.styleSheet() != dark) + apply_theme("dark") + qtbot.waitUntil(lambda: box.view.styleSheet() == dark)