Pages
API Documentation
On this page

KDualAction Class

An action which can alternate between two texts/icons when triggered. More...

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

List of all members, including inherited members

Public Functions

Public Slots

Signals

Detailed Description

KDualAction should be used when you want to create an action which alternate between two states when triggered but which should not be rendered as a checkable widget because it is more appropriate to change the text and icon of the action instead.

You should use KDualAction to implement this kind of actions instead of KToggleAction because KToggleAction is rendered as a checkable widget: this means one of your state will have a checkbox in a menu and will be represented as a sunken button in a toolbar.

Porting from KToggleAction to KDualAction:

  1. If you used the KToggleAction constructor which accepts the action text, adjust the constructor: KDualAction constructor accepts both inactive and active text.

  2. Replace connections to the checked(bool) signal with a connection to the activeChanged(bool) (or activeChangedByUser(bool))

  3. Replace calls to setChecked()/isChecked() with setActive()/isActive()

  4. Replace calls to setCheckedState(guiItem) with setActiveGuiItem(guiItem)

Member Function Documentation

[explicit] KDualAction::KDualAction(QObject *parent)

Constructs a KDualAction with the specified parent. Texts must be set with setTextForState() or setGuiItemForState().

KDualAction::KDualAction(const QString &inactiveText, const QString &activeText, QObject *parent)

Constructs a KDualAction with the specified parent and texts.

[signal] void KDualAction::activeChanged(bool)

Emitted when the state changes. This signal is emitted when the user trigger the action and when setActive() is called.

[signal] void KDualAction::activeChangedByUser(bool)

Only emitted when the state changes because the user triggered the action.

KGuiItem KDualAction::activeGuiItem() const

Gets the KGuiItem for the active state

See also setActiveGuiItem()

QIcon KDualAction::activeIcon() const

Gets the icon for the active state

See also setActiveIcon()

QString KDualAction::activeText() const

Gets the text for the active state

See also setActiveText()

QString KDualAction::activeToolTip() const

Gets the tooltip for the active state

See also setActiveToolTip()

bool KDualAction::autoToggle() const

Returns whether the current action will automatically be changed when the user triggers this action. The default value is true.

See also setAutoToggle()

KGuiItem KDualAction::inactiveGuiItem() const

Gets the KGuiItem for the inactive state

See also setInactiveGuiItem()

QIcon KDualAction::inactiveIcon() const

Gets the icon for the inactive state

See also setInactiveIcon()

QString KDualAction::inactiveText() const

Gets the text for the inactive state

See also setInactiveText()

QString KDualAction::inactiveToolTip() const

Gets the tooltip for the inactive state

See also setInactiveToolTip()

bool KDualAction::isActive() const

Returns the action state. The action is inactive by default.

[slot] void KDualAction::setActive(bool state)

Sets the action state. activeChanged() will be emitted but not activeChangedByUser().

See also isActive()

void KDualAction::setActiveGuiItem(const KGuiItem &)

Sets the KGuiItem for the active state

See also activeGuiItem()

void KDualAction::setActiveIcon(const QIcon &)

Sets the icon for the active state

See also activeIcon()

void KDualAction::setActiveText(const QString &)

Sets the text for the active state

See also activeText()

void KDualAction::setActiveToolTip(const QString &)

Sets the tooltip for the active state

See also activeToolTip()

void KDualAction::setAutoToggle(bool)

Defines whether the current action should automatically be changed when the user triggers this action.

See also autoToggle()

void KDualAction::setIconForStates(const QIcon &icon)

Convenience method to set the icon for both active and inactive states.

void KDualAction::setInactiveGuiItem(const KGuiItem &)

Sets the KGuiItem for the inactive state

See also inactiveGuiItem()

void KDualAction::setInactiveIcon(const QIcon &)

Sets the icon for the inactive state

See also inactiveIcon()

void KDualAction::setInactiveText(const QString &)

Sets the text for the inactive state

See also inactiveText()

void KDualAction::setInactiveToolTip(const QString &)

Sets the tooltip for the inactive state

See also inactiveToolTip()

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