KDE 4.7 PyKDE API Reference

- KDE's Python API

# KShortcut Class Reference

`from PyKDE4.kdeui import *`

## Detailed Description

Represents a keyboard shortcut

The KShortcut class is used to represent a keyboard shortcut to an action. A shortcut is normally a single key with modifiers, such as Ctrl+V. A KShortcut object may also contain an alternate key sequence which will also activate the action it's associated with, as long as no other actions have defined that key as their primary key. Ex: Ctrl+V;Shift+Insert.

This can be used to add additional accelerators to a KAction. For example, the below code binds the escape key to the close action.

      KAction *closeAction = KStandardAction.close(this, SLOT( close() ), actionCollection());
      KShortcut closeShortcut = closeAction->shortcut();
      closeShortcut.setAlternate(Qt.Key_Escape);
      closeAction->setShortcut(closeShortcut);

## Enumerations
EmptyHandling | { KeepEmpty, RemoveEmpty }
## Methods
| __init__ (self)
| __init__ (self, QKeySequence primary)
| __init__ (self, QKeySequence primary, QKeySequence alternate)
| __init__ (self, int keyQtPri, int keyQtAlt=0)
| __init__ (self, KShortcut other)
| __init__ (self, QString description)
| __init__ (self, [QKeySequence] seqs)
QKeySequence | alternate (self)
bool | conflictsWith (self, QKeySequence needle)
bool | contains (self, QKeySequence needle)
bool | isEmpty (self)
bool | operator != (self, KShortcut other)
bool | operator == (self, KShortcut other)
QKeySequence | primary (self)
| remove (self, QKeySequence keySeq, KShortcut.EmptyHandling handleEmpty=KShortcut.RemoveEmpty)
| setAlternate (self, QKeySequence keySeq)
| setPrimary (self, QKeySequence keySeq)
[QKeySequence] | toList (self, KShortcut.EmptyHandling handleEmpty=KShortcut.RemoveEmpty)
QString | toString (self)
QString | toString (self, QKeySequence::SequenceFormat format)

## Method Documentation

__init__ | ( |  | self ) |

Creates a new empty shortcut.

See also:
  isEmpty()

See also:
  clear()

__init__ | ( | self, |
|  | QKeySequence | primary
| ) |  |  |

Creates a new shortcut that contains the given Qt key sequence as primary shortcut.

Parameters:

  | primary | Qt key sequence to add

__init__ | ( | self, |
|  | QKeySequence | primary,
|  | QKeySequence | alternate
| ) |  |  |

Creates a new shortcut with the given Qt key sequences as primary and secondary shortcuts.

Parameters:

  | primary | Qt keycode of primary shortcut
  | alternate | Qt keycode of alternate shortcut

See also:
  Qt.Key

__init__ | ( | self, |
|  | int | keyQtPri,
|  | int | keyQtAlt=0
| ) |  |  |

Creates a new shortcut with the given Qt key codes as primary and secondary shortcuts. You can only assign single-key shortcuts this way.

Parameters:

  | keyQtPri | Qt keycode of primary shortcut
  | keyQtAlt | Qt keycode of alternate shortcut

See also:
  Qt.Key

__init__ | ( | self, |
|  | KShortcut | other
| ) |  |  |

Copy constructor.

__init__ | ( | self, |
|  | QString | description
| ) |  |  |

Creates a new shortcut that contains the key sequences described in description. The format of description is the same as used in QKeySequence.fromString(const QString&). Up to two key sequences separated by a semicolon followed by a space "; " may be given.

Parameters:

  | description | the description of key sequence(s)

See also:
  QKeySequence.fromString(const QString&, SequenceFormat)

__init__ | ( | self, |
|  | [QKeySequence] | seqs
| ) |  |  |

Creates a new shortcut with the given Qt key sequences. The first sequence in the list is considered to be the primary sequence, the second one the alternate.

Parameters:

  | seqs | List of key sequeces.

QKeySequence alternate | ( |  | self ) |

Returns the alternate key sequence of this shortcut.

Returns:
  alternate key sequence

bool conflictsWith | ( | self, |
|  | QKeySequence | needle
| ) |  |  |

Returns whether at least one of the key sequences conflicts witho needle.

Returns:
  whether this shortcut conflicts with needle

bool contains | ( | self, |
|  | QKeySequence | needle
| ) |  |  |

Returns whether at least one of the key sequences is equal to needle.

Returns:
  whether this shortcut contains needle

bool isEmpty | ( |  | self ) |

Returns whether this shortcut contains any nonempty key sequences.

Returns:
  whether this shortcut is empty

bool operator != | ( | self, |
|  | KShortcut | other
| ) |  |  |

bool operator == | ( | self, |
|  | KShortcut | other
| ) |  |  |

QKeySequence primary | ( |  | self ) |

Returns the primary key sequence of this shortcut.

Returns:
  primary key sequence

remove | ( | self, |
|  | QKeySequence | keySeq,
|  | KShortcut.EmptyHandling | handleEmpty=KShortcut.RemoveEmpty
| ) |  |  |

Remove keySeq from this shortcut. If handleEmpty equals RemoveEmpty, following key sequences will move up to take the place of keySeq. Otherwise, key sequences equal to keySeq will be set to empty.

Parameters:

  | keySeq | remove this key sequence from the shortcut

setAlternate | ( | self, |
|  | QKeySequence | keySeq
| ) |  |  |

Set the alternate key sequence of this shortcut to the given key sequence.

Parameters:

  | keySeq | set alternate key sequence to this

setPrimary | ( | self, |
|  | QKeySequence | keySeq
| ) |  |  |

Set the primary key sequence of this shortcut to the given key sequence.

Parameters:

  | keySeq | set primary key sequence to this

[QKeySequence] toList | ( | self, |
|  | KShortcut.EmptyHandling | handleEmpty=KShortcut.RemoveEmpty
| ) |  |  |

The same as operator QList<QKeySequence>() If handleEmpty equals RemoveEmpty, empty key sequences will be left out of the result. Otherwise, empy key sequences will be included; you can be sure that shortcut.alternate() == shortcut.toList(KeepEmpty).at(1).

Returns:
  the shortcut converted to a QList<QKeySequence>

QString toString | ( |  | self ) |

Returns a description of the shortcut as a semicolon-separated list of key sequences, as returned by QKeySequence.toString().

Returns:
  the string represenation of this shortcut

See also:
  QKeySequence.toString()

See also:
  KShortcut(const QString &description)

Since:
  KDE 4.2

QString toString | ( | self, |
|  | QKeySequence::SequenceFormat | format
| ) |  |  |

Returns a description of the shortcut as a semicolon-separated list of key sequences, as returned by QKeySequence.toString().

Returns:
  the string represenation of this shortcut

See also:
  QKeySequence.toString()

See also:
  KShortcut(const QString &description)

Since:
  KDE 4.2

## Enumeration Documentation

EmptyHandling

An enum about the behavior of operations that treat a KShortcut like a list of QKeySequences.

Enumerator:

  KeepEmpty = 0 |
  RemoveEmpty |