Pages
API Documentation
On this page

KGuiItem Class

An abstract class for setting the text, icon, tooltip and WhatsThis data on a GUI item (e.g. a QPushButton). More...

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

List of all members, including inherited members

Public Functions

Static Public Members

Detailed Description

See also KStandardGuiItem

Member Function Documentation

KGuiItem::KGuiItem()

Constructs an empty KGuiItem. You can use the various methods provided by this class to set the text, icon... etc.

KGuiItem::KGuiItem(const QString &text, const QIcon &icon, const QString &toolTip = QString(), const QString &whatsThis = QString())

Constructs a KGuiItem with the provided arguments.

text the text to use with the GUI item

icon the QIcon object used to get an icon to display next to the text on this item

toolTip the tooltip to use for this item

whatsThis the text to use for the WhatThis help message

[explicit] KGuiItem::KGuiItem(const QString &text, const QString &iconName = QString(), const QString &toolTip = QString(), const QString &whatsThis = QString())

Constructs a KGuiItem with the provided arguments.

text the text to use with the GUI item

iconName the name of the icon to display next to the text on the item; QIcon::fromTheme() is used to get a icon with that name from the icon themes available on the system

tooltip the tooltip to use for this item

whatsThis the text to use for the WhatThis help message

[static] void KGuiItem::assign(QPushButton *button, const KGuiItem &item)

A static method that can be used to set the text, icon, tooltip and WhatThis properties from item on button.

// Create a QDialogButtonBox with two buttons, of Yes and No standard type
auto *buttonBox = new QDialogButtonBox({QDialogButtonBox::Yes | QDialogButtonBox::No}, this);

// Assign the text and icon from KStandardGuiItem::quit()/continue() to the buttons in the
// button dialog box
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), KStandardGuiItem::quit());
KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), KStandardGuiItem::continue());

bool KGuiItem::hasIcon() const

Returns true if this GUI item has an icon set for it and false otherwise.

QIcon KGuiItem::icon() const

Returns the icon used by this GUI item.

This will return a null QIcon if no icon was previously set for this item.

See also setIcon()

QString KGuiItem::iconName() const

Returns the name of the icon used by this GUI item.

This will return an empty string if no icon was previously set for this item.

See also setIconName()

bool KGuiItem::isEnabled() const

Returns true if this GUI item is enabled and false otherwise.

See also QWidget::isEnabled()

QString KGuiItem::plainText() const

Returns the text used by this GUI item after stripping all existing '&' characters which denote keyboard accelerators.

See also text()

void KGuiItem::setEnabled(bool enable)

Toggles the enabled property of this GUI item.

See also isEnabled(), QWidget::setEnabled()

void KGuiItem::setIcon(const QIcon &iconset)

Sets the icon to be shown next to the text of this GUI item.

See also icon()

void KGuiItem::setIconName(const QString &iconName)

Sets the name of the icon that will be shown next to the text of this GUI item. The actual QIcon will be obtained by using QIcon::fromTheme().

See also iconName()

void KGuiItem::setText(const QString &text)

Sets the text to use for this GUI item.

See also text()

void KGuiItem::setToolTip(const QString &tooltip)

Sets the tooltip text.

See also toolTip()

void KGuiItem::setWhatsThis(const QString &whatsThis)

Sets the WhatThis text.

See also whatsThis()

QString KGuiItem::text() const

Returns the text used by this GUI item.

This may contain '&' characters which denote a keyboard accelerator shortcut that can be used to invoke the GUI item, e.g. Alt + 'O' for button "&OK". (Note that the '&' is not visible to the user).

You can get the plain text without the accelerator denoting character '&', by using plainText().

See also setText()

QString KGuiItem::toolTip() const

Returns the tooltip used for this GUI item.

This will return an empty string if no tooltip was previously set for this item.

See also setToolTip()

QString KGuiItem::whatsThis() const

Returns the WhatThis text used for this GUI item.

This will return an empty string if no WhatThis text was previously set for this item.

See also setWhatsThis()

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