mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-07-21 04:01:07 +02:00
fix: minimum size hint for QElidingLabel (#260)
This commit is contained in:
@@ -73,3 +73,10 @@ class QElidingLabel(_GenericEliding, QLabel):
|
||||
flags = int(self.alignment() | Qt.TextFlag.TextWordWrap)
|
||||
r = fm.boundingRect(QRect(QPoint(0, 0), self.size()), flags, self._text)
|
||||
return QSize(self.width(), r.height())
|
||||
|
||||
def minimumSizeHint(self) -> QSize:
|
||||
# The smallest that self._elidedText can be is just the ellipsis.
|
||||
fm = QFontMetrics(self.font())
|
||||
flags = int(self.alignment() | Qt.TextFlag.TextWordWrap)
|
||||
r = fm.boundingRect(QRect(QPoint(0, 0), self.size()), flags, "...")
|
||||
return QSize(r.width(), r.height())
|
||||
|
@@ -69,3 +69,14 @@ def test_wrap_text():
|
||||
assert isinstance(wrap, list)
|
||||
assert all(isinstance(x, str) for x in wrap)
|
||||
assert 9 <= len(wrap) <= 13
|
||||
|
||||
|
||||
def test_minimum_size_hint():
|
||||
# The hint should always just be the space needed for "..."
|
||||
wdg = QElidingLabel()
|
||||
size_hint = wdg.minimumSizeHint()
|
||||
# Regardless of what text is contained
|
||||
wdg.setText(TEXT)
|
||||
new_hint = wdg.minimumSizeHint()
|
||||
assert size_hint.width() == new_hint.width()
|
||||
assert size_hint.height() == new_hint.height()
|
||||
|
Reference in New Issue
Block a user