def sizeHint(self, which, constraint=QSizeF()): if which == Qt.PreferredSize: sh = self.__naturalsh() if 0 < constraint.height() < sh.height(): sh = scaled(sh, constraint, Qt.KeepAspectRatioByExpanding) return sh return super().sizeHint(which, constraint)