KDE 4.7 PyKDE API Reference

- KDE's Python API

# KDualAction Class Reference

`from PyKDE4.kdeui import *`

Inherits: KAction → QWidgetAction → QAction → QObject

## Detailed Description

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

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)

Author:
  Aurélien Gâteau <agateau@kde.org>

Since:
  4.6

## Signals
| activeChanged (bool a0)
| activeChangedByUser (bool a0)
## Methods
| __init__ (self, QObject parent)
| __init__ (self, QString inactiveText, QString activeText, QObject parent)
KGuiItem | activeGuiItem (self)
QIcon | activeIcon (self)
QString | activeText (self)
QString | activeToolTip (self)
bool | autoToggle (self)
KGuiItem | inactiveGuiItem (self)
QIcon | inactiveIcon (self)
QString | inactiveText (self)
QString | inactiveToolTip (self)
bool | isActive (self)
| setActive (self, bool state)
| setActiveGuiItem (self, KGuiItem a0)
| setActiveIcon (self, QIcon a0)
| setActiveText (self, QString a0)
| setActiveToolTip (self, QString a0)
| setAutoToggle (self, bool a0)
| setIconForStates (self, QIcon icon)
| setInactiveGuiItem (self, KGuiItem a0)
| setInactiveIcon (self, QIcon a0)
| setInactiveText (self, QString a0)
| setInactiveToolTip (self, QString a0)

## Signal Documentation

activeChanged | ( | bool | a0
| ) |  |  |

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

Signal syntax:
  `QObject.connect(source, SIGNAL("activeChanged(bool)"), target_slot)`

activeChangedByUser | ( | bool | a0
| ) |  |  |

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

Signal syntax:
  `QObject.connect(source, SIGNAL("activeChangedByUser(bool)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent
| ) |  |  |

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

__init__ | ( | self, |
|  | QString | inactiveText,
|  | QString | activeText,
|  | QObject | parent
| ) |  |  |

Constructs a KDualAction with the specified parent and texts.

KGuiItem activeGuiItem | ( |  | self ) |

Gets the KGuiItem for the active state

QIcon activeIcon | ( |  | self ) |

Gets the icon for the active state

QString activeText | ( |  | self ) |

Gets the text for the active state

QString activeToolTip | ( |  | self ) |

Gets the tooltip for the active state

bool autoToggle | ( |  | self ) |

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

KGuiItem inactiveGuiItem | ( |  | self ) |

Gets the KGuiItem for the inactive state

QIcon inactiveIcon | ( |  | self ) |

Gets the icon for the inactive state

QString inactiveText | ( |  | self ) |

Gets the text for the inactive state

QString inactiveToolTip | ( |  | self ) |

Gets the tooltip for the inactive state

bool isActive | ( |  | self ) |

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

setActive | ( | self, |
|  | bool | state
| ) |  |  |

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

setActiveGuiItem | ( | self, |
|  | KGuiItem | a0
| ) |  |  |

Sets the KGuiItem for the active state

setActiveIcon | ( | self, |
|  | QIcon | a0
| ) |  |  |

Sets the icon for the active state

setActiveText | ( | self, |
|  | QString | a0
| ) |  |  |

Sets the text for the active state

setActiveToolTip | ( | self, |
|  | QString | a0
| ) |  |  |

Sets the tooltip for the active state

setAutoToggle | ( | self, |
|  | bool | a0
| ) |  |  |

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

setIconForStates | ( | self, |
|  | QIcon | icon
| ) |  |  |

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

setInactiveGuiItem | ( | self, |
|  | KGuiItem | a0
| ) |  |  |

Sets the KGuiItem for the inactive state

setInactiveIcon | ( | self, |
|  | QIcon | a0
| ) |  |  |

Sets the icon for the inactive state

setInactiveText | ( | self, |
|  | QString | a0
| ) |  |  |

Sets the text for the inactive state

setInactiveToolTip | ( | self, |
|  | QString | a0
| ) |  |  |

Sets the tooltip for the inactive state