From 2efd48736cbe04e84533f7933c552ea8274e2162 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 29 Aug 2024 10:14:25 +0200 Subject: [PATCH] fix(toolbar): widget action added --- bec_widgets/qt_utils/toolbar.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bec_widgets/qt_utils/toolbar.py b/bec_widgets/qt_utils/toolbar.py index 01700f0a..a7fd142b 100644 --- a/bec_widgets/qt_utils/toolbar.py +++ b/bec_widgets/qt_utils/toolbar.py @@ -142,6 +142,31 @@ class DeviceSelectionAction(ToolBarAction): self.device_combobox.setStyleSheet(f"QComboBox {{ background-color: {color}; }}") +class WidgetAction(ToolBarAction): + """ + Action for adding any widget to the toolbar. + + Args: + label (str|None): The label for the widget. + widget (QWidget): The widget to be added to the toolbar. + + """ + + def __init__(self, label: str | None = None, widget: QWidget = None): + super().__init__() + self.label = label + self.widget = widget + + def add_to_toolbar(self, toolbar, target): + widget = QWidget() + layout = QHBoxLayout(widget) + if self.label is not None: + label = QLabel(f"{self.label}") + layout.addWidget(label) + layout.addWidget(self.widget) + toolbar.addWidget(widget) + + class ExpandableMenuAction(ToolBarAction): """ Action for an expandable menu in the toolbar.