Size view delegate from monkey patched parent

fsp_feeds
Tyler Goodlet 2021-07-25 15:07:02 -04:00
parent 940aafe1be
commit 5ec00ee762
1 changed files with 13 additions and 6 deletions

View File

@ -108,12 +108,11 @@ class FontAndChartAwareLineEdit(QLineEdit):
class FontScaledDelegate(QStyledItemDelegate): class FontScaledDelegate(QStyledItemDelegate):
""" '''
Super simple view delegate to render text in the same Super simple view delegate to render text in the same
font size as the search widget. font size as the search widget.
""" '''
def __init__( def __init__(
self, self,
@ -136,8 +135,13 @@ class FontScaledDelegate(QStyledItemDelegate):
# value = index.data() # value = index.data()
# br = self.dpi_font.boundingRect(value) # br = self.dpi_font.boundingRect(value)
# w, h = br.width(), br.height() # w, h = br.width(), br.height()
w, h = self.parent()._max_item_size parent = self.parent()
return QSize(w, h)
if getattr(parent, '_max_item_size', None):
return QSize(*self.parent()._max_item_size)
else:
return super().sizeHint(option, index)
class FieldsForm(QtGui.QWidget): class FieldsForm(QtGui.QWidget):
@ -238,6 +242,7 @@ class FieldsForm(QtGui.QWidget):
QSizePolicy.Fixed, QSizePolicy.Fixed,
) )
view = select.view() view = select.view()
view.setUniformItemSizes(True)
view.setItemDelegate(FontScaledDelegate(view)) view.setItemDelegate(FontScaledDelegate(view))
# compute maximum item size so that the weird # compute maximum item size so that the weird
@ -246,12 +251,14 @@ class FieldsForm(QtGui.QWidget):
values.sort() values.sort()
br = _font.boundingRect(str(values[-1])) br = _font.boundingRect(str(values[-1]))
w, h = br.width(), br.height() w, h = br.width(), br.height()
# TODO: something better then this monkey patch
view._max_item_size = w, h view._max_item_size = w, h
view.setUniformItemSizes(True)
# limit to 6 items? # limit to 6 items?
view.setMaximumHeight(6*h) view.setMaximumHeight(6*h)
select.show() select.show()
self.hbox.addWidget(select) self.hbox.addWidget(select)
return select return select