QElidingLabel¶
A QLabel that elides its text: when the
text is too long to fit, its end is replaced with an ellipsis ("…"). text()
still returns the full text.
setElideModesets which part of the text is elided (the end, by default; or the start or the middle), with aQt.TextElideMode.- With
setWordWrap(True), the text wraps onto as many lines as fit, and only the last line is elided.
For a line edit that does the same, see QElidingLineEdit.
from qtpy.QtWidgets import QApplication
from superqt import QElidingLabel
app = QApplication([])
label = QElidingLabel(
"This text is too long for the label, so the end of it is replaced with an "
"ellipsis. Make the window wider to see more of it."
)
label.resize(300, 20)
label.show()
app.exec()
QElidingLabel
¶
A QLabel variant that will elide text (could add '…') to fit width.
QElidingLabel() QElidingLabel(parent: Optional[QWidget], f: Qt.WindowFlags = ...) QElidingLabel(text: str, parent: Optional[QWidget] = None, f: Qt.WindowFlags = ...)
For a multiline eliding label, use setWordWrap(True). In this case, text
will wrap to fit the width, and only the last line will be elided.
When wordWrap() is True, sizeHint() will return the size required to fit
the full text.
Subclass of QLabel
QElidingLabel inherits all of QLabel's methods, signals, and properties. Only those that superqt adds or changes are listed here.
Methods¶
A QLabel variant that will elide text (could add '…') to fit width.
QElidingLabel() QElidingLabel(parent: Optional[QWidget], f: Qt.WindowFlags = ...) QElidingLabel(text: str, parent: Optional[QWidget] = None, f: Qt.WindowFlags = ...)
For a multiline eliding label, use setWordWrap(True). In this case, text
will wrap to fit the width, and only the last line will be elided.
When wordWrap() is True, sizeHint() will return the size required to fit
the full text.
setEllipsesWidth
¶
setEllipsesWidth(width: int) -> None
A width value to take into account ellipses width when eliding text.
The value is deducted from the widget width when computing the elided version of the text.
setText
¶
setText(txt: str) -> None
Set the label's text.
Setting the text clears any previous content. NOTE: we set the QLabel private text to the elided version