Class: QgsShortcutsManager¶
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()
.
Class Hierarchy¶
Base classes¶
Methods
Returns an action by its name, or |
|
Returns the action which is associated for a shortcut sequence, or |
|
Returns the default sequence for an action. |
|
Returns a list of all actions in the manager. |
|
Returns a list of both actions and shortcuts in the manager. |
|
Returns a list of shortcuts in the manager. |
|
Returns the default sequence for an object (either a QAction or QShortcut). |
|
Returns the object (QAction or QShortcut) matching the specified key sequence, |
|
Returns the QShortcut or QAction matching the the full setting key Return None if the key was not found |
|
Returns the full settings key matching the QShortcut or QAction Return an empty QString if the QObject is not registered |
|
Registers an action with the manager so the shortcut can be configured in GUI. |
|
Automatically registers all QActions which are children of the passed object. |
|
Automatically registers all QShortcuts which are children of the passed object. |
|
Automatically registers all QActions and QShortcuts which are children of the passed object. |
|
Registers a QShortcut with the manager so the shortcut can be configured in GUI. |
|
Modifies an action or shortcut's key sequence. |
|
Modifies an object's (either a QAction or a QShortcut) key sequence. |
|
Returns the root settings path used to store shortcut customization. |
|
Returns a shortcut by its name, or |
|
Returns the shortcut which is associated for a key sequence, or |
|
Removes an action from the manager. |
|
Removes a shortcut from the manager. |
- class qgis.gui.QgsShortcutsManager[source]¶
Bases:
QObject
- __init__(parent: QObject | None = None, settingsRoot: str | None = '')
Constructor for QgsShortcutsManager.
- Parameters:
parent (Optional[QObject] = None) – parent object
settingsRoot (Optional[str] = '') – root
QgsSettings
path for storing settings, e.g., “/myplugin/shortcuts”. Leave as the default value to store settings alongside built in QGIS shortcuts, but care must be taken to not register actions which conflict with the built in QGIS actions.
- actionByName(self, name: str | None) QAction | None [source]¶
Returns an action by its name, or
None
if nothing found.- Parameters:
name (Optional[str]) – action name. Must match QAction’s text.
See also
- Return type:
Optional[QAction]
- actionForSequence(self, sequence: QKeySequence | QKeySequence.StandardKey | str | None | int) QAction | None [source]¶
Returns the action which is associated for a shortcut sequence, or
None
if no action is associated.- Parameters:
sequence (Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int]) – shortcut key sequence
See also
See also
- Return type:
Optional[QAction]
- defaultKeySequence(self, action: QAction | None) str [source]¶
Returns the default sequence for an action. An empty return string indicates no default sequence.
- Parameters:
action (Optional[QAction]) – action to return default key sequence for
See also
- Return type:
str
- defaultKeySequence(self, shortcut: QShortcut | None) str [source]
Returns the default sequence for a shortcut. An empty return string indicates no default sequence.
- Parameters:
shortcut (Optional[QShortcut]) – shortcut to return default key sequence for
See also
- Return type:
str
- listActions(self) List[QAction] ¶
Returns a list of all actions in the manager.
See also
See also
- Return type:
List[QAction]
- listAll(self) List[QObject] ¶
Returns a list of both actions and shortcuts in the manager.
See also
See also
- Return type:
List[QObject]
- listShortcuts(self) List[QShortcut] ¶
Returns a list of shortcuts in the manager.
See also
See also
- Return type:
List[QShortcut]
- objectDefaultKeySequence(self, object: QObject | None) str [source]¶
Returns the default sequence for an object (either a QAction or QShortcut). An empty return string indicates no shortcut.
- Parameters:
object (Optional[QObject]) – QAction or QShortcut to return default key sequence for
See also
- Return type:
str
- objectForSequence(self, sequence: QKeySequence | QKeySequence.StandardKey | str | None | int) QObject | None [source]¶
Returns the object (QAction or QShortcut) matching the specified key sequence,
- Parameters:
sequence (Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int]) – key sequence to find
- Return type:
Optional[QObject]
- Returns:
object with matching sequence, or
None
if not found
See also
See also
- objectForSettingKey(self, name: str | None) QObject | None [source]¶
Returns the QShortcut or QAction matching the the full setting key Return None if the key was not found
Added in version 3.30.
- Parameters:
name (Optional[str])
- Return type:
Optional[QObject]
- objectSettingKey(self, object: QObject | None) str [source]¶
Returns the full settings key matching the QShortcut or QAction Return an empty QString if the QObject is not registered
Added in version 3.30.
- Parameters:
object (Optional[QObject])
- Return type:
str
- registerAction(self, action: QAction | None, defaultShortcut: str | None = '', section: str | None = '') bool [source]¶
Registers an action with the manager so the shortcut can be configured in GUI.
- Parameters:
action (Optional[QAction]) – action to register. The action must have a unique text string for identification.
defaultShortcut (Optional[str] = '') – default key sequence for action
section (Optional[str] = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)
- Return type:
bool
- Returns:
True
if action was successfully registered
See also
See also
See also
- registerAllChildActions(self, object: QObject | None, recursive: bool = False, section: str | None = '')[source]¶
Automatically registers all QActions which are children of the passed object.
- Parameters:
object (Optional[QObject]) – parent object containing actions to register
recursive (bool = False) – set to
True
to recursively add child actionssection (Optional[str] = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)
See also
See also
See also
- registerAllChildShortcuts(self, object: QObject | None, recursive: bool = False, section: str | None = '')[source]¶
Automatically registers all QShortcuts which are children of the passed object.
- Parameters:
object (Optional[QObject]) – parent object containing shortcuts to register
recursive (bool = False) – set to
True
to recursively add child shortcutssection (Optional[str] = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)
See also
See also
See also
- registerAllChildren(self, object: QObject | None, recursive: bool = False, section: str | None = '')[source]¶
Automatically registers all QActions and QShortcuts which are children of the passed object.
- Parameters:
object (Optional[QObject]) – parent object containing actions and shortcuts to register
recursive (bool = False) – set to
True
to recursively add child actions and shortcutssection (Optional[str] = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)
See also
See also
- registerShortcut(self, shortcut: QShortcut | None, defaultSequence: str | None = '', section: str | None = '') bool [source]¶
Registers a QShortcut with the manager so the shortcut can be configured in GUI.
- Parameters:
shortcut (Optional[QShortcut]) – QShortcut to register. The shortcut must have a unique QObject.objectName() for identification.
defaultSequence (Optional[str] = '') – default key sequence for shortcut
section (Optional[str] = '') – Allows disambiguating shortcuts with the same objectName (since QGIS 3.32)
- Return type:
bool
- Returns:
True
if shortcut was successfully registered
See also
See also
- setKeySequence(self, name: str | None, sequence: str | None) bool [source]¶
Modifies an action or shortcut’s key sequence.
- Parameters:
name (Optional[str]) – name of action or shortcut to modify. Must match the action’s QAction.text() or the shortcut’s QObject.objectName()
sequence (Optional[str]) – new shortcut key sequence
See also
- Return type:
bool
- setKeySequence(self, action: QAction | None, sequence: str | None) bool [source]
Modifies an action’s key sequence.
- Parameters:
action (Optional[QAction]) – action to modify
sequence (Optional[str]) – new shortcut key sequence
See also
- Return type:
bool
- setKeySequence(self, shortcut: QShortcut | None, sequence: str | None) bool [source]
Modifies a shortcuts’s key sequence.
- Parameters:
shortcut (Optional[QShortcut]) – QShortcut to modify
sequence (Optional[str]) – new shortcut key sequence
See also
- Return type:
bool
- setObjectKeySequence(self, object: QObject | None, sequence: str | None) bool [source]¶
Modifies an object’s (either a QAction or a QShortcut) key sequence.
- Parameters:
object (Optional[QObject]) – QAction or QShortcut to modify
sequence (Optional[str]) – new shortcut key sequence
See also
- Return type:
bool
- settingsPath(self) str [source]¶
Returns the root settings path used to store shortcut customization.
- Return type:
str
- shortcutByName(self, name: str | None) QShortcut | None [source]¶
Returns a shortcut by its name, or
None
if nothing found- Parameters:
name (Optional[str]) – shortcut name. Must match QShortcut’s QObject.objectName() property.
See also
- Return type:
Optional[QShortcut]
- shortcutForSequence(self, sequence: QKeySequence | QKeySequence.StandardKey | str | None | int) QShortcut | None [source]¶
Returns the shortcut which is associated for a key sequence, or
None
if no shortcut is associated.- Parameters:
sequence (Union[QKeySequence, QKeySequence.StandardKey, Optional[str], int]) – shortcut key sequence
See also
See also
- Return type:
Optional[QShortcut]
- unregisterAction(self, action: QAction | None) bool [source]¶
Removes an action from the manager.
- Parameters:
action (Optional[QAction]) – action to remove
- Return type:
bool
- Returns:
True
if action was previously registered in manager and has been removed, orFalse
if action was not previously registered in manager
See also
See also
- unregisterShortcut(self, shortcut: QShortcut | None) bool [source]¶
Removes a shortcut from the manager.
- Parameters:
shortcut (Optional[QShortcut]) – shortcut to remove
- Return type:
bool
- Returns:
True
if shortcut was previously registered in manager and has been removed, orFalse
if shortcut was not previously registered in manager
See also
See also