From 1f2f4824bfced79b78c7e250fd48e4523b845d58 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Tue, 2 Jul 2024 11:27:02 +0200 Subject: [PATCH] fix(widget_io): added option to set value of combobox by str --- bec_widgets/utils/widget_io.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bec_widgets/utils/widget_io.py b/bec_widgets/utils/widget_io.py index 92b08ee8..1ff3e1d8 100644 --- a/bec_widgets/utils/widget_io.py +++ b/bec_widgets/utils/widget_io.py @@ -44,8 +44,11 @@ class ComboBoxHandler(WidgetHandler): def get_value(self, widget: QComboBox) -> int: return widget.currentIndex() - def set_value(self, widget: QComboBox, value: int) -> None: - widget.setCurrentIndex(value) + def set_value(self, widget: QComboBox, value: int | str) -> None: + if isinstance(value, str): + value = widget.findText(value) + if isinstance(value, int): + widget.setCurrentIndex(value) class TableWidgetHandler(WidgetHandler):