From 6b5aa74934b171fd45fbf4614321a7234c3a5148 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Mon, 27 Oct 2025 19:05:59 +0100 Subject: [PATCH] fix(toolbar): create_action_with_text text will not change to tooltip when disable/enable/checked --- bec_widgets/utils/toolbars/actions.py | 8 +++++++- bec_widgets/utils/toolbars/toolbar.py | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/bec_widgets/utils/toolbars/actions.py b/bec_widgets/utils/toolbars/actions.py index 9cfc88ac..8d87e032 100644 --- a/bec_widgets/utils/toolbars/actions.py +++ b/bec_widgets/utils/toolbars/actions.py @@ -43,13 +43,19 @@ def create_action_with_text(toolbar_action, toolbar: QToolBar): """ btn = QToolButton(parent=toolbar) + if getattr(toolbar_action, "label_text", None): + toolbar_action.action.setText(toolbar_action.label_text) + if getattr(toolbar_action, "tooltip", None): + toolbar_action.action.setToolTip(toolbar_action.tooltip) + btn.setToolTip(toolbar_action.tooltip) + btn.setDefaultAction(toolbar_action.action) btn.setAutoRaise(True) if toolbar_action.text_position == "under": btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) else: btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) - btn.setText(toolbar_action.label_text) + toolbar.addWidget(btn) diff --git a/bec_widgets/utils/toolbars/toolbar.py b/bec_widgets/utils/toolbars/toolbar.py index c1b7b7f2..4b10fba8 100644 --- a/bec_widgets/utils/toolbars/toolbar.py +++ b/bec_widgets/utils/toolbars/toolbar.py @@ -6,7 +6,7 @@ from collections import defaultdict from typing import DefaultDict, Literal from bec_lib.logger import bec_logger -from qtpy.QtCore import QSize, Qt +from qtpy.QtCore import QSize, Qt, QTimer from qtpy.QtGui import QAction, QColor from qtpy.QtWidgets import QApplication, QLabel, QMainWindow, QMenu, QToolBar, QVBoxLayout, QWidget @@ -492,10 +492,33 @@ if __name__ == "__main__": # pragma: no cover self.toolbar.connect_bundle( "base", PerformanceConnection(self.toolbar.components, self) ) + self.toolbar.components.add_safe( + "text", + MaterialIconAction( + "text_fields", + tooltip="Test Text Action", + checkable=True, + label_text="text", + text_position="under", + ), + ) self.toolbar.show_bundles(["performance", "plot_export"]) self.toolbar.get_bundle("performance").add_action("save") + self.toolbar.get_bundle("performance").add_action("text") self.toolbar.refresh() + # Timer to disable and enable text button each 2s + self.timer = QTimer() + self.timer.timeout.connect(self.toggle_text_action) + self.timer.start(2000) + + def toggle_text_action(self): + text_action = self.toolbar.components.get_action("text") + if text_action.action.isEnabled(): + text_action.action.setEnabled(False) + else: + text_action.action.setEnabled(True) + def enable_fps_monitor(self, enabled: bool): """ Example method to enable or disable FPS monitoring.