Reputation: 13
I feel like I miss something extremely obvious, but couldn't find anything on it.
I have a custom item delegate for which I set the sizeHint height to 50, but the print statement returns a rectangle that is double the height.
def sizeHint(self, option, index):
print("sizehint:", option.rect)
s = QtCore.QSize()
s.setWidth(option.rect.width())
s.setHeight(50)
return s
#output
sizehint: PySide2.QtCore.QRect(0, 0, 498, 100)
Upvotes: 0
Views: 537
Reputation: 243897
The "option.rect" is the rectangle that the view recommends taking into account the generic information that it has (for example the size of the font, the width of the header, etc.) that the delegate must take as reference for its painting or interaction, The rectangle does not take the information of each element (the information that you want to display) from time to time, so the delegate offers the sizeHint() as the recommended size. Actually if you want to get the default size then you should use super.
def sizeHint(self, option, index):
default_size_hint = super().sizeHint(option, index)
print("sizehint:", default_size_hint)
return QtCore.QSize(option.rect.width(), 50)
Upvotes: 1