-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.10.0
-
None
QML Shortcut documentation is short...
For example, it doesn't explain we can create several shortcuts with the same sequence and enable one, like for a radio button.
Basic example to test this feature:
Shortcut {
id: shortcut1
sequence: StandardKey.MoveToPreviousPage
enabled: true
onActivated: {
console.info('shortcut1')
enabled = false
shortcut2.enabled = true
}
}
Shortcut {
id: shortcut2
sequence: StandardKey.MoveToPreviousPage
enabled: false
onActivated: {
console.info('shortcut2')
enabled = false
shortcut1.enabled = true
}
}
To explore use cases, we can give a look to the sophisticated Emacs key maps:
- https://www.gnu.org/software/emacs/manual/html_node/emacs/Keymaps.html
- https://www.gnu.org/software/emacs/manual/html_node/elisp/Keymaps.html
Which implements modes and an active keymap, which is a merge of the global and locales keymaps.
A basic use case is to share a shortcut for several actions depending on the current application mode. Then the question is how we should implement the mapping ?
—
Further info
QML Shortcut is implemented in
- qtdeclarative/src/quick/util/qquickshortcut.cpp
- qtbase/src/gui/kernel/qshortcutmap.cpp
Shorcuts are stored in QGuiApplication
QGuiApplicationPrivate *pApp = QGuiApplicationPrivate::instance();
shortcut.id = pApp->shortcutMap.addShortcut(this, shortcut.keySequence, context, *ctxMatcher());