Skip to content

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.

  • setElideMode sets which part of the text is elided (the end, by default; or the start or the middle), with a Qt.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.

QElidingLabel QElidingLabel
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

QElidingLabel(*args, **kwargs)

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.

elideMode

elideMode() -> TextElideMode

The current Qt.TextElideMode.

full_text

full_text() -> str

The current text without eliding.

setElideMode

setElideMode(mode: TextElideMode) -> None

Set the elide mode to a Qt.TextElideMode.

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

setWordWrap

setWordWrap(wrap: bool) -> None

text

text() -> str

Return the label's text.

If no text has been set this will return an empty string.

wrapText

wrapText(text, width, font=None) -> list[str]

Returns text, split as it would be wrapped for width, given font.

Static method.