Class: QgsShortcutsManager

class qgis.gui.QgsShortcutsManager

Bases: PyQt5.QtCore.QObject

Shortcuts manager is a class that contains a list of QActions and QShortcuts that have been registered and their shortcuts can be changed.

QgsShortcutsManager is not usually directly created, but rather accessed through QgsGui.shortcutsManager().

QgsShortcutsManager(parent: QObject = None, settingsRoot: str = ‘’) Constructor for QgsShortcutsManager.

Parameters:
actionByName(self, name: str) QAction

Returns an action by its name, or None if nothing found.

Parameters:

name (str) – action name. Must match QAction’s text.

See also

shortcutByName()

Return type:

QAction

actionForSequence(self, sequence: QKeySequence | QKeySequence.StandardKey | str | int) QAction

Returns the action which is associated for a shortcut sequence, or None if no action is associated.

Parameters:

sequence (Union[QKeySequence) – shortcut key sequence

Return type:

QAction

childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
defaultKeySequence(self, action: QAction) str

Returns the default sequence for an action. An empty return string indicates no default sequence.

Parameters:

action (QAction) – action to return default key sequence for

defaultKeySequence(self, shortcut: QShortcut) -> str Returns the default sequence for a shortcut. An empty return string indicates no default sequence.

Parameters:

shortcut – shortcut to return default key sequence for

Return type:

str

disconnectNotify(self, QMetaMethod)
isSignalConnected(self, QMetaMethod) bool
listActions(self) List[QAction]

Returns a list of all actions in the manager.

See also

listShortcuts()

See also

listAll()

Return type:

List[QAction]

listAll(self) List[QObject]

Returns a list of both actions and shortcuts in the manager.

See also

listActions()

See also

listShortcuts()

Return type:

List[QObject]

listShortcuts(self) List[QShortcut]

Returns a list of shortcuts in the manager.

See also

listActions()

See also

listAll()

Return type:

List[QShortcut]

objectDefaultKeySequence(self, object: QObject) str

Returns the default sequence for an object (either a QAction or QShortcut). An empty return string indicates no shortcut.

Parameters:

object (QObject) – QAction or QShortcut to return default key sequence for

Return type:

str

objectForSequence(self, sequence: QKeySequence | QKeySequence.StandardKey | str | int) QObject

Returns the object (QAction or QShortcut) matching the specified key sequence,

Parameters:

sequence (Union[QKeySequence) – key sequence to find

Return type:

QObject

Returns:

object with matching sequence, or None if not found

objectForSettingKey(self, name: str) QObject

Returns the QShortcut or QAction matching the the full setting key Return None if the key was not found

New in version 3.30.

Parameters:

name (str) –

Return type:

QObject

objectSettingKey(self, object: QObject) str

Returns the full settings key matching the QShortcut or QAction Return an empty QString if the QObject is not registered

New in version 3.30.

Parameters:

object (QObject) –

Return type:

str

receivers(self, PYQT_SIGNAL) int
registerAction(self, action: QAction, defaultShortcut: str = '', section: str = '') bool

Registers an action with the manager so the shortcut can be configured in GUI.

Parameters:
  • action (QAction) – action to register. The action must have a unique text string for identification.

  • defaultShortcut (str = '') – default key sequence for action

  • section (str = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)

Return type:

bool

Returns:

True if action was successfully registered

registerAllChildActions(self, object: QObject, recursive: bool = False, section: str = '')

Automatically registers all QActions which are children of the passed object.

Parameters:
  • object (QObject) – parent object containing actions to register

  • recursive (bool = False) – set to True to recursively add child actions

  • section (str = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)

See also

registerAction()

registerAllChildShortcuts(self, object: QObject, recursive: bool = False, section: str = '')

Automatically registers all QShortcuts which are children of the passed object.

Parameters:
  • object (QObject) – parent object containing shortcuts to register

  • recursive (bool = False) – set to True to recursively add child shortcuts

  • section (str = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)

registerAllChildren(self, object: QObject, recursive: bool = False, section: str = '')

Automatically registers all QActions and QShortcuts which are children of the passed object.

Parameters:
  • object (QObject) – parent object containing actions and shortcuts to register

  • recursive (bool = False) – set to True to recursively add child actions and shortcuts

  • section (str = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)

registerShortcut(self, shortcut: QShortcut, defaultSequence: str = '', section: str = '') bool

Registers a QShortcut with the manager so the shortcut can be configured in GUI.

Parameters:
  • shortcut (QShortcut) – QShortcut to register. The shortcut must have a unique QObject.objectName() for identification.

  • defaultSequence (str = '') – default key sequence for shortcut

  • section (str = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)

Return type:

bool

Returns:

True if shortcut was successfully registered

See also

registerAction()

sender(self) QObject
senderSignalIndex(self) int
setKeySequence(self, name: str, sequence: str) bool

Modifies an action or shortcut’s key sequence.

Parameters:
  • name (str) – name of action or shortcut to modify. Must match the action’s QAction.text() or the shortcut’s QObject.objectName()

  • sequence (str) – new shortcut key sequence

setKeySequence(self, action: QAction, sequence: str) -> bool Modifies an action’s key sequence.

Parameters:
  • action – action to modify

  • sequence – new shortcut key sequence

setKeySequence(self, shortcut: QShortcut, sequence: str) -> bool Modifies a shortcuts’s key sequence.

Parameters:
  • shortcut – QShortcut to modify

  • sequence – new shortcut key sequence

Return type:

bool

setObjectKeySequence(self, object: QObject, sequence: str) bool

Modifies an object’s (either a QAction or a QShortcut) key sequence.

Parameters:
  • object (QObject) – QAction or QShortcut to modify

  • sequence (str) – new shortcut key sequence

See also

setKeySequence()

Return type:

bool

settingsPath(self) str

Returns the root settings path used to store shortcut customization.

Return type:

str

shortcutByName(self, name: str) QShortcut

Returns a shortcut by its name, or None if nothing found

Parameters:

name (str) – shortcut name. Must match QShortcut’s QObject.objectName() property.

See also

actionByName()

Return type:

QShortcut

shortcutForSequence(self, sequence: QKeySequence | QKeySequence.StandardKey | str | int) QShortcut

Returns the shortcut which is associated for a key sequence, or None if no shortcut is associated.

Parameters:

sequence (Union[QKeySequence) – shortcut key sequence

Return type:

QShortcut

timerEvent(self, QTimerEvent)
unregisterAction(self, action: QAction) bool

Removes an action from the manager.

Parameters:

action (QAction) – action to remove

Return type:

bool

Returns:

True if action was previously registered in manager and has been removed, or False if action was not previously registered in manager

See also

registerAction()

unregisterShortcut(self, shortcut: QShortcut) bool

Removes a shortcut from the manager.

Parameters:

shortcut (QShortcut) – shortcut to remove

Return type:

bool

Returns:

True if shortcut was previously registered in manager and has been removed, or False if shortcut was not previously registered in manager