def METHOD_NAME(self):
    count = self.count()
    height = self.sizeHintForRow(0) * count if count else 0
    # !!!ACHTUNG!!!
    # !!! Qt Bug !!!
    # Qt never shrinks QListWidget vertically to less than the size
    # that is required to contain list three items. Even if there a no items.
    # sizeHint is ignored completely, the real minimum size is always at least
    # three items. Also, Qt ignores the overloaded self.maximumHeight method.
    # So, the only way to shrink it is to call setMaximumHeight manually.
    # Qt, I hate you! Why are you doing this to me!?
    self.setMaximumHeight(height)
    return QSize(self.width(), height)