# class KShortcut

###

Module | kdeui
Namespace |
Class | KShortcut
Inherits |

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);

### enums

- EmptyHandling { KeepEmpty, RemoveEmpty }

enum details

### methods

- KShortcut ( )

  returns ctor

  Creates a new empty shortcut.

  See also isEmpty()

  See also clear()

- KShortcut (primary)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  primary | QKeySequence |

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

  primary - Qt key sequence to add

- KShortcut (primary, alternate)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  primary | QKeySequence |
  alternate | QKeySequence |

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

  primary - Qt keycode of primary shortcut

  alternate - Qt keycode of alternate shortcut

  See also Qt.Key

- KShortcut (keyQtPri, keyQtAlt)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  keyQtPri | int |
  keyQtAlt | int | 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.

  keyQtPri - Qt keycode of primary shortcut

  keyQtAlt - Qt keycode of alternate shortcut

  See also Qt.Key

- KShortcut (other)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  other | KShortcut |

  Copy constructor.

- KShortcut (description)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  description | QString |

  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.

  description - the description of key sequence(s)

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

- KShortcut (seqs)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  seqs | QList<QKeySequence> |

  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.

  seqs - List of key sequeces.

- KShortcut (a0)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | QKeySequence |

- KShortcut (a0, a1)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | int |
  a1 | int | 0

- KShortcut (a0)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | QString |

- KShortcut (a0)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | QList<QKeySequence> |

- alternate ( )

  returns QKeySequence

  Returns the alternate key sequence of this shortcut. Returns alternate key sequence

- contains (needle)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  needle | QKeySequence |

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

- isEmpty ( )

  returns bool

  Returns whether this shortcut contains any nonempty key sequences. Returns whether this shortcut is empty

- operator != (other)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  other | KShortcut |

- operator == (other)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  other | KShortcut |

- primary ( )

  returns QKeySequence

  Returns the primary key sequence of this shortcut. Returns primary key sequence

- remove (keySeq, handleEmpty)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  keySeq | QKeySequence |
  handleEmpty | KShortcut.EmptyHandling | 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.

  keySeq - remove this key sequence from the shortcut

- setAlternate (keySeq)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  keySeq | QKeySequence |

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

  keySeq - set alternate key sequence to this

- setPrimary (keySeq)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  keySeq | QKeySequence |

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

  keySeq - set primary key sequence to this

- toList (handleEmpty)

  returns QList<QKeySequence>

  Argument | Type | Default
  --- | --- | ---
  handleEmpty | KShortcut.EmptyHandling | 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\>

- toString ( )

  returns QString

  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)

### enums - detail

- EmptyHandling { KeepEmpty, RemoveEmpty }

  if a shortcut is or becomes empty, let it stay as a placeholder

  | KeepEmpty | - 0 | - |
  | RemoveEmpty | - | - |