Skip to content

labels

_labels

Custom label widgets.

Classes:

Name Description
FXElidedLabel

A QLabel that elides text with '...' when it doesn't fit.

Classes

FXElidedLabel

FXElidedLabel(
    text: str = "",
    parent: Optional[QWidget] = None,
    mode: TextElideMode = ElideRight,
)

Bases: QLabel


              flowchart TD
              fxgui.fxwidgets._labels.FXElidedLabel[FXElidedLabel]

              

              click fxgui.fxwidgets._labels.FXElidedLabel href "" "fxgui.fxwidgets._labels.FXElidedLabel"
            

A QLabel that elides text with '...' when it doesn't fit.

This label automatically truncates text and adds an ellipsis when the text is too long to fit within the available space.

Parameters:

Name Type Description Default
text
str

The label's text. Defaults to "".

''
parent
Optional[QWidget]

Parent widget. Defaults to None.

None
mode
TextElideMode

Where the text is cut when it does not fit. Defaults to Qt.ElideRight. Qt.ElideMiddle is what tells apart strings that share a tail -- paths under a common root, or email-shaped identities at one domain, where two long values cut from the right come out looking identical.

Governs the SINGLE-LINE case only. With wordWrap() on, the text is cut at the last line that fits and an ellipsis is appended there, whatever the mode -- because QFontMetrics.elidedText elides one line, and there is no one obvious meaning for "elide the middle" of a wrapped block (which line loses its middle?). Enabling word wrap on a label whose mode is not ElideRight warns, rather than quietly doing something else than it was asked.

ElideRight

Examples:

>>> from qtpy.QtCore import Qt
>>> from fxgui import fxwidgets
>>> label = fxwidgets.FXElidedLabel(
...     "a very long identity", mode=Qt.ElideMiddle
... )

Methods:

Name Description
minimumSizeHint

No width at all, and the height one line of this font needs.

resizeEvent

Re-elide text when the label is resized.

setText

Set the text and store the full text for elision.

setWordWrap

Wrap the text, and say so if that makes mode moot.

Attributes:

Name Type Description
mode TextElideMode

Where the text is cut when it does not fit.

Attributes
mode property writable
mode: TextElideMode

Where the text is cut when it does not fit.

Methods:
minimumSizeHint
minimumSizeHint() -> QSize

No width at all, and the height one line of this font needs.

QLabel's own minimum width IS the width of its whole text -- measured, 696px for a 58-character string -- and a minimum is not a preference: a label that will not go below its own text width does not elide when the room runs out, it takes the room from whatever shares its row and, failing that, from the window. Measured: a 47-character string in a row with a button, in a window told to be 200px wide, forced the window to 680px and pushed the button from x=90 to x=570.

Which makes an eliding label with QLabel's minimum a widget that cannot do the one thing it exists for. This yields the width instead, which is what eliding means, and keeps the height so a row is still a row.

Returns:

Name Type Description
QSize QSize

Zero width, at QLabel's own minimum height.

resizeEvent
resizeEvent(event) -> None

Re-elide text when the label is resized.

setText
setText(text: str) -> None

Set the text and store the full text for elision.

setWordWrap
setWordWrap(wrap: bool) -> None

Wrap the text, and say so if that makes mode moot.

Parameters:

Name Type Description Default
wrap bool

Whether the label wraps rather than eliding on one line.

required