KDE 4.9 PyKDE API Reference

- KDE's Python API

# KActionCollection Class Reference

`from PyKDE4.kdeui import *`

Inherits: QObject

## Detailed Description

A container for a set of QAction objects.

KActionCollection manages a set of QAction objects. It allows them to be grouped for organized presentation of configuration to the user, saving + loading of configuration, and optionally for automatic plugging into specified widget(s).

Additionally, KActionCollection provides several convenience functions for locating named actions, and actions grouped by QActionGroup.

Note:
  If you create your own action collection and need to assign shortcuts to the actions within, you have to call associateWidget() or addAssociatedWidget() to have them working.

## Signals

| actionHighlighted (QAction action)
| actionHovered (QAction action)
| actionTriggered (QAction action)
| inserted (QAction action)
| removed (QAction action)

## Methods

| __init__ (self, QObject parent, KComponentData cData=KComponentData())
| __init__ (self, KXMLGUIClient parent)
QAction | action (self, int index)
QAction | action (self, QString name)
[QActionGroup] | actionGroups (self)
[QAction] | actions (self)
[QAction] | actionsWithoutGroup (self)
QAction | addAction (self, QString name, QAction action)
KAction | addAction (self, QString name, KAction action)
KAction | addAction (self, KStandardAction.StandardAction actionType, QObject receiver=0, QString member=0)
KAction | addAction (self, KStandardAction.StandardAction actionType, QString name, QObject receiver=0, QString member=0)
KAction | addAction (self, QString name, QObject receiver=0, QString member=0)
| addAssociatedWidget (self, QWidget widget)
| associateWidget (self, QWidget widget)
[QWidget] | associatedWidgets (self)
| clear (self)
| clearAssociatedWidgets (self)
KComponentData | componentData (self)
QString | configGroup (self)
bool | configIsGlobal (self)
| connectNotify (self, SIP_SIGNAL a0)
int | count (self)
| exportGlobalShortcuts (self, KConfigGroup config, bool writeDefaults=0)
| importGlobalShortcuts (self, KConfigGroup config)
bool | isEmpty (self)
KXMLGUIClient | parentGUIClient (self)
| readSettings (self, KConfigGroup config=0)
| removeAction (self, QAction action)
| removeAssociatedWidget (self, QWidget widget)
| setComponentData (self, KComponentData componentData)
| setConfigGlobal (self, bool global)
| setConfigGroup (self, QString group)
| slotActionHighlighted (self)
| slotActionTriggered (self)
QAction | takeAction (self, QAction action)
| writeSettings (self, KConfigGroup config=0, bool writeDefaults=0, QAction oneAction=0)

## Static Methods

[KActionCollection] | allCollections ()

## Signal Documentation

actionHighlighted | ( | QAction | action
| ) |  |  |

Indicates that action was highlighted (hovered over).

Deprecated:
  Replaced by actionHovered(QAction* action);

Signal syntax:
  `QObject.connect(source, SIGNAL("actionHighlighted(QAction*)"), target_slot)`

actionHovered | ( | QAction | action
| ) |  |  |

Indicates that action was hovered.

Signal syntax:
  `QObject.connect(source, SIGNAL("actionHovered(QAction*)"), target_slot)`

actionTriggered | ( | QAction | action
| ) |  |  |

Indicates that action was triggered

Signal syntax:
  `QObject.connect(source, SIGNAL("actionTriggered(QAction*)"), target_slot)`

inserted | ( | QAction | action
| ) |  |  |

Indicates that action was inserted into this action collection.

Signal syntax:
  `QObject.connect(source, SIGNAL("inserted(QAction*)"), target_slot)`

removed | ( | QAction | action
| ) |  |  |

Indicates that action was removed from this action collection.

Deprecated:

Signal syntax:
  `QObject.connect(source, SIGNAL("removed(QAction*)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent,
|  | KComponentData | cData=KComponentData()
| ) |  |  |

Constructor. Allows specification of a KComponentData other than the default global KComponentData, where needed.

__init__ | ( | self, |
|  | KXMLGUIClient | parent
| ) |  |  |

QAction action | ( | self, |
|  | int | index
| ) |  |  |

Get the action with the given name from the action collection.

Parameters:

  | name | Name of the KAction

Returns:
  A pointer to the KAction in the collection which matches the parameters or null if nothing matches.

QAction action | ( | self, |
|  | QString | name
| ) |  |  |

Get the action with the given name from the action collection.

Parameters:

  | name | Name of the KAction

Returns:
  A pointer to the KAction in the collection which matches the parameters or null if nothing matches.

[QActionGroup] actionGroups | ( |  | self ) |

Returns the list of all QActionGroups associated with actions in this action collection.

[QAction] actions | ( |  | self ) |

Returns the list of KActions which belong to this action collection.

The list is guaranteed to be in the same order the action were put into the collection.

[QAction] actionsWithoutGroup | ( |  | self ) |

Returns the list of KActions without an QAction.actionGroup() which belong to this action collection.

QAction addAction | ( | self, |
|  | QString | name,
|  | QAction | action
| ) |  |  |

Creates a new action under the given name to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is returned.

NOTE: KDE prior to 4.2 used the triggered() signal instead of the triggered(bool) signal.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection.

Parameters:

  | name | The name by which the action be retrieved again from the collection.
  | receiver | The QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
  | member | The SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.

Returns:
  new action of the given type ActionType.

KAction addAction | ( | self, |
|  | QString | name,
|  | KAction | action
| ) |  |  |

Creates a new action under the given name to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is returned.

NOTE: KDE prior to 4.2 used the triggered() signal instead of the triggered(bool) signal.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection.

Parameters:

  | name | The name by which the action be retrieved again from the collection.
  | receiver | The QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
  | member | The SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.

Returns:
  new action of the given type ActionType.

KAction addAction | ( | self, |
|  | KStandardAction.StandardAction | actionType,
|  | QObject | receiver=0,
|  | QString | member=0
| ) |  |  |

Creates a new action under the given name to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is returned.

NOTE: KDE prior to 4.2 used the triggered() signal instead of the triggered(bool) signal.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection.

Parameters:

  | name | The name by which the action be retrieved again from the collection.
  | receiver | The QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
  | member | The SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.

Returns:
  new action of the given type ActionType.

KAction addAction | ( | self, |
|  | KStandardAction.StandardAction | actionType,
|  | QString | name,
|  | QObject | receiver=0,
|  | QString | member=0
| ) |  |  |

Creates a new action under the given name to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is returned.

NOTE: KDE prior to 4.2 used the triggered() signal instead of the triggered(bool) signal.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection.

Parameters:

  | name | The name by which the action be retrieved again from the collection.
  | receiver | The QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
  | member | The SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.

Returns:
  new action of the given type ActionType.

KAction addAction | ( | self, |
|  | QString | name,
|  | QObject | receiver=0,
|  | QString | member=0
| ) |  |  |

Creates a new action under the given name to the collection and connects the action's triggered(bool) signal to the specified receiver/member. The newly created action is returned.

NOTE: KDE prior to 4.2 used the triggered() signal instead of the triggered(bool) signal.

Inserting an action that was previously inserted under a different name will replace the old entry, i.e. the action will not be available under the old name anymore but only under the new one.

Inserting an action under a name that is already used for another action will replace the other action in the collection.

Parameters:

  | name | The name by which the action be retrieved again from the collection.
  | receiver | The QObject to connect the triggered(bool) signal to. Leave 0 if no connection is desired.
  | member | The SLOT to connect the triggered(bool) signal to. Leave 0 if no connection is desired.

Returns:
  new action of the given type ActionType.

addAssociatedWidget | ( | self, |
|  | QWidget | widget
| ) |  |  |

Associate all actions in this collection to the given widget, including any actions added after this association is made.

This does not change the action's shortcut context, so if you need to have the actions only trigger when the widget has focus, you'll need to set the shortcut context on each action to Qt.WidgetShortcut (or better still, Qt.WidgetWithChildrenShortcut with Qt 4.4+)

associateWidget | ( | self, |
|  | QWidget | widget
| ) |  |  |

Associate all actions in this collection to the given widget. Unlike addAssociatedWidget, this method only adds all current actions in the collection to the given widget. Any action added after this call will not be added to the given widget automatically. So this is just a shortcut for a foreach loop and a widget->addAction call.

[QWidget] associatedWidgets | ( |  | self ) |

Return a list of all associated widgets.

clear | ( |  | self ) |

Clears the entire action collection, deleting all actions.

clearAssociatedWidgets | ( |  | self ) |

Clear all associated widgets and remove the actions from those widgets.

KComponentData componentData | ( |  | self ) |

The KComponentData with which this class is associated.

QString configGroup | ( |  | self ) |

Returns the KConfig group with which settings will be loaded and saved.

bool configIsGlobal | ( |  | self ) |

Returns whether this action collection's configuration should be global to KDE ( true ), or specific to the application ( false ).

connectNotify | ( | self, |
|  | SIP_SIGNAL | a0
| ) |  |  |

int count | ( |  | self ) |

Returns the number of actions in the collection.

This is equivalent to actions().count().

exportGlobalShortcuts | ( | self, |
|  | KConfigGroup | config,
|  | bool | writeDefaults=0
| ) |  |  |

Export the current configurable global key associations to config.

Since:
  4.1

Parameters:

  | config | Config object to save to

Parameters:

  | writeDefaults | set to true to write settings which are already at defaults.

importGlobalShortcuts | ( | self, |
|  | KConfigGroup | config
| ) |  |  |

Import from config all configurable global key associations.

Since:
  4.1

Parameters:

  | config | Config object to read from

bool isEmpty | ( |  | self ) |

Returns whether the action collection is empty or not.

KXMLGUIClient parentGUIClient | ( |  | self ) |

The parent KXMLGUIClient, or null if not available.

readSettings | ( | self, |
|  | KConfigGroup | config=0
| ) |  |  |

Read all key associations from config.

If config is zero, read all key associations from the application's configuration file KGlobal.config(), in the group set by setConfigGroup().

removeAction | ( | self, |
|  | QAction | action
| ) |  |  |

Removes an action from the collection and deletes it.

Parameters:

  | action | The action to remove.

removeAssociatedWidget | ( | self, |
|  | QWidget | widget
| ) |  |  |

Remove an association between all actions in this collection and the given widget, i.e. remove those actions from the widget, and stop associating newly added actions as well.

setComponentData | ( | self, |
|  | KComponentData | componentData
| ) |  |  |

Set the componentData associated with this action collection.

Warning:
  Don't call this method on a KActionCollection that contains actions. This is not supported.

Parameters:

  | componentData | the KComponentData which is to be associated with this action collection, or an invalid KComponentData instance to indicate the default KComponentData.

setConfigGlobal | ( | self, |
|  | bool | global
| ) |  |  |

Set whether this action collection's configuration should be global to KDE ( true ), or specific to the application ( false ).

setConfigGroup | ( | self, |
|  | QString | group
| ) |  |  |

Sets group as the KConfig group with which settings will be loaded and saved.

slotActionHighlighted | ( |  | self ) |

Internal:

Deprecated:
  Replaced by slotActionHovered();

slotActionTriggered | ( |  | self ) |

QAction takeAction | ( | self, |
|  | QAction | action
| ) |  |  |

Removes an action from the collection.

Parameters:

  | action | the action to remove.

writeSettings | ( | self, |
|  | KConfigGroup | config=0,
|  | bool | writeDefaults=0,
|  | QAction | oneAction=0
| ) |  |  |

Write the current configurable key associations to config. What the function does if config is zero depends. If this action collection belongs to a KXMLGuiClient the setting are saved to the kxmlgui definition file. If not the settings are written to the applications config file.

Note:
  oneAction() and writeDefaults() have no meaning for the kxmlgui configuration file.

Parameters:

  | config | Config object to save to, or null (see above)

Parameters:

  | writeDefaults | set to true to write settings which are already at defaults.

Parameters:

  | oneAction | pass an action here if you just want to save the values for one action, eg. if you know that action is the only one which has changed.

## Static Method Documentation

[KActionCollection] allCollections | ( |  | ) |

Access the list of all action collections in existence for this app