Try to set icons on RHS, store combo box entries in map

chart_mod_breakup
Tyler Goodlet 2021-09-12 19:29:42 -04:00
parent 07214f2044
commit d08886dceb
1 changed files with 19 additions and 3 deletions

View File

@ -157,6 +157,13 @@ class FontScaledDelegate(QStyledItemDelegate):
else: else:
return super().sizeHint(option, index) 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: # slew of resources which helped get this where it is:
# https://stackoverflow.com/questions/20648210/qcombobox-adjusttocontents-changing-height # https://stackoverflow.com/questions/20648210/qcombobox-adjusttocontents-changing-height
@ -280,10 +287,16 @@ class FieldsForm(QWidget):
label = self.add_field_label(label_name) label = self.add_field_label(label_name)
select = QComboBox(self) select = QComboBox(self)
select._key = key select._key = key
select._items: dict[str, int] = {}
for i, value in enumerate(values): 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( select.setStyleSheet(
f"""QComboBox {{ f"""QComboBox {{
@ -293,14 +306,15 @@ class FieldsForm(QWidget):
""" """
) )
select.setSizeAdjustPolicy(QComboBox.AdjustToContents) select.setSizeAdjustPolicy(QComboBox.AdjustToContents)
select.setIconSize(QSize(0, 0))
self.setSizePolicy( self.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.Fixed,
QSizePolicy.Fixed, QSizePolicy.Fixed,
) )
view = select.view() view = select.view()
view.setUniformItemSizes(True) 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 # compute maximum item size so that the weird
# "style item delegate" thing can then specify # "style item delegate" thing can then specify
@ -309,6 +323,8 @@ class FieldsForm(QWidget):
br = _font.boundingRect(str(values[-1])) br = _font.boundingRect(str(values[-1]))
_, h = br.width(), br.height() _, h = br.width(), br.height()
select.setIconSize(QSize(h, h))
# TODO: something better then this monkey patch # TODO: something better then this monkey patch
# view._max_item_size = w, h # view._max_item_size = w, h