From 62daa67539840bb54abe4a7c4ad59d30e2d9d670 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Tue, 10 Oct 2023 16:53:28 -0400 Subject: [PATCH] change with palette --- src/magicgui/backends/_qtpy/widgets.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/magicgui/backends/_qtpy/widgets.py b/src/magicgui/backends/_qtpy/widgets.py index 4fffda7f7..a94bd3665 100644 --- a/src/magicgui/backends/_qtpy/widgets.py +++ b/src/magicgui/backends/_qtpy/widgets.py @@ -1222,13 +1222,21 @@ class ToolBar(QBaseWidget): def __init__(self, **kwargs: Any) -> None: super().__init__(QtW.QToolBar, **kwargs) + self._qwidget.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon) + self._event_filter.paletteChanged.connect(self._on_palette_change) + + def _on_palette_change(self): + for action in self._qwidget.actions(): + if icon := action.data(): + if qicon := _get_qicon(icon, None, palette=self._qwidget.palette()): + action.setIcon(qicon) def _mgui_add_button(self, text: str, icon: str, callback: Callable) -> None: """Add an action to the toolbar.""" + act = self._qwidget.addAction(text, callback) if qicon := _get_qicon(icon, None, palette=self._qwidget.palette()): - self._qwidget.addAction(qicon, text, callback) - else: - self._qwidget.addAction(text, callback) + act.setIcon(qicon) + act.setData(icon) def _mgui_add_separator(self) -> None: """Add a separator line to the toolbar."""