Skip to content

QElidingLabel#

QLabel variant that will elide text (i.e. add an ellipsis) if it is too long to fit in the available space.

from qtpy.QtWidgets import QApplication

from superqt import QElidingLabel

app = QApplication([])

widget = QElidingLabel(
    "a skj skjfskfj sdlf sdfl sdlfk jsdf sdlkf jdsf dslfksdl sdlfk sdf sdl "
    "fjsdlf kjsdlfk laskdfsal as lsdfjdsl kfjdslf asfd dslkjfldskf sdlkfj"
)
widget.setWordWrap(True)
widget.resize(300, 20)
widget.show()

app.exec_()

QElidingLabel

Qt Class#

QLabel

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.

setElideMode(mode: Qt.TextElideMode) -> None #

Set the elide mode to a Qt.TextElideMode.

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.