Pages
API Documentation
On this page

KSqueezedTextLabel Class

A replacement for QLabel that squeezes its text into the label. More...

  • Header: #include <KSqueezedTextLabel>
  • CMake: find_package(KF6 REQUIRED COMPONENTS WidgetsAddons)
    target_link_libraries(mytarget PRIVATE KF6::WidgetsAddons)
  • Inherits: QLabel

List of all members, including inherited members

Properties

Public Functions

Public Slots

Detailed Description

If the text is too long to fit into the label it is divided into remaining left and right parts which are separated by three dots. Hovering the mouse over the label shows the full text in a tooltip.

Example: http://www.kde.org/documentation/index.html could be squeezed to http://www.kde...ion/index.html

To change the position of the elision mark to the left or right end of the text, use setTextElideMode().

Note: Several functions of KSqueezedTextLabel (indicated by a warning in their description) reimplement non-virtual functions of QLabel. Therefore, you may need to cast the object to KSqueezedTextLabel in some situations:

KSqueezedTextLabel* squeezed = new KSqueezedTextLabel("text", parent);
QLabel* label = squeezed;
label->setText("new text");    // this will not work
squeezed->setText("new text"); // works as expected
static_cast<KSqueezedTextLabel*>(label)->setText("new text");  // works as expected

Property Documentation

indent : int

Access functions:

margin : int

Access functions:

textElideMode : Qt::TextElideMode

Access functions:

Member Function Documentation

[explicit] KSqueezedTextLabel::KSqueezedTextLabel(QWidget *parent = nullptr)

Default constructor.

parent the label's parent object

[explicit] KSqueezedTextLabel::KSqueezedTextLabel(const QString &text, QWidget *parent = nullptr)

text the text that will be displayed

parent the label's parent object

[slot] void KSqueezedTextLabel::clear()

Clears the text.

Reimplementation of QLabel::clear().

Warning: The corresponding function in the base class is not virtual. Therefore make sure to call this function on objects of type KSqueezedTextLabel, as shown in the example in the class description.

QRect KSqueezedTextLabel::contentsRect() const

Returns the rectangle to squeeze the text into

Reimplementation of QLabel::contentsRect().

Warning: The corresponding function in the base class is not virtual. Therefore make sure to call this function on objects of type KSqueezedTextLabel, as shown in the example in the class description.

QString KSqueezedTextLabel::fullText() const

Returns the full text set via setText()

bool KSqueezedTextLabel::isSqueezed() const

Returns true if the text displayed is currently squeezed, i.e. the original text does not fit inside the space available and elide mode is set to a value other than Qt::ElideNone.

[override virtual] QSize KSqueezedTextLabel::minimumSizeHint() const

Reimplements: QLabel::minimumSizeHint() const.

Returnss the label's minimum size, where the horizontal component will be -1 to indicate the label's ability to shrink its width by squeezing the text

void KSqueezedTextLabel::setIndent(int indent)

Sets the indentation of the label.

indent the amount of indentation in pixels

Reimplementation of QLabel::setIndent().

Warning: The corresponding function in the base class is not virtual. Therefore make sure to call this function on objects of type KSqueezedTextLabel, as shown in the example in the class description.

Note: Setter function for property indent.

void KSqueezedTextLabel::setMargin(int margin)

Sets the margin of the label.

margin the margin size in pixels

Reimplementation of QLabel::setMargin().

Warning: The corresponding function in the base class is not virtual. Therefore make sure to call this function on objects of type KSqueezedTextLabel, as shown in the example in the class description.

Note: Setter function for property margin.

[slot] void KSqueezedTextLabel::setText(const QString &text)

Sets the text.

text The new text.

Reimplementation of QLabel::setText().

Warning: The corresponding function in the base class is not virtual. Therefore make sure to call this function on objects of type KSqueezedTextLabel, as shown in the example in the class description.

void KSqueezedTextLabel::setTextElideMode(Qt::TextElideMode mode)

Sets the text elide mode.

mode The text elide mode.

Note: Setter function for property textElideMode.

See also textElideMode()

[override virtual] QSize KSqueezedTextLabel::sizeHint() const

Reimplements: QLabel::sizeHint() const.

Returns the label's preferred size, which is wide enough to display the text without squeezing it

Qt::TextElideMode KSqueezedTextLabel::textElideMode() const

Returns the text elide mode

Note: Getter function for property textElideMode.

See also setTextElideMode()

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.