From d08886dcebfc623e867db5b879efe018cf417e80 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 12 Sep 2021 19:29:42 -0400 Subject: [PATCH] Try to set icons on RHS, store combo box entries in map --- piker/ui/_forms.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/piker/ui/_forms.py b/piker/ui/_forms.py index 9e7e40ea..a97ae762 100644 --- a/piker/ui/_forms.py +++ b/piker/ui/_forms.py @@ -157,6 +157,13 @@ class FontScaledDelegate(QStyledItemDelegate): else: return super().sizeHint(option, index) + # TODO: is there a way to set this stype option once? + def paint(self, painter, option, index): + # display icons on RHS + # https://stackoverflow.com/a/39943629 + option.decorationPosition = QtGui.QStyleOptionViewItem.Right + super().paint(painter, option, index) + # slew of resources which helped get this where it is: # https://stackoverflow.com/questions/20648210/qcombobox-adjusttocontents-changing-height @@ -280,10 +287,16 @@ class FieldsForm(QWidget): label = self.add_field_label(label_name) select = QComboBox(self) + select._key = key + select._items: dict[str, int] = {} for i, value in enumerate(values): - select.insertItem(i, str(value)) + strkey = str(value) + select.insertItem(i, strkey) + + # store map of entry keys to row indexes + select._items[strkey] = i select.setStyleSheet( f"""QComboBox {{ @@ -293,14 +306,15 @@ class FieldsForm(QWidget): """ ) select.setSizeAdjustPolicy(QComboBox.AdjustToContents) - select.setIconSize(QSize(0, 0)) + self.setSizePolicy( QSizePolicy.Fixed, QSizePolicy.Fixed, ) view = select.view() view.setUniformItemSizes(True) - view.setItemDelegate(FontScaledDelegate(view)) + # TODO: this doesn't seem to work for the currently selected item? + select.setItemDelegate(FontScaledDelegate(self)) # compute maximum item size so that the weird # "style item delegate" thing can then specify @@ -309,6 +323,8 @@ class FieldsForm(QWidget): br = _font.boundingRect(str(values[-1])) _, h = br.width(), br.height() + select.setIconSize(QSize(h, h)) + # TODO: something better then this monkey patch # view._max_item_size = w, h