Shortcut QML Type

Provides keyboard shortcuts. More...

Import Statement: import QtQuick

Properties

Signals

Detailed Description

The Shortcut type lets you handle keyboard shortcuts. The shortcut can be set to one of the standard keyboard shortcuts, or it can be described with a string containing a sequence of up to four key presses that are needed to activate the shortcut.

Item {
    id: view

    property int currentIndex

    Shortcut {
        sequences: [StandardKey.NextChild]
        onActivated: view.currentIndex++
    }
}

It is also possible to set multiple shortcut sequences, so that the shortcut can be activated via several different sequences of key presses.

See also Keys and shortcutOverride().

Property Documentation

autoRepeat : bool

This property holds whether the shortcut can auto repeat.

The default value is true.


context : enumeration

This property holds the shortcut context.

Supported values are:

ConstantDescription
Qt.WindowShortcut(default) The shortcut is active when its parent item is in an active top-level window.
Qt.ApplicationShortcutThe shortcut is active when one of the application's windows are active.
Shortcut {
    sequence: StandardKey.Quit
    context: Qt.ApplicationShortcut
    onActivated: Qt.quit()
}

enabled : bool

This property holds whether the shortcut is enabled.

The default value is true.


[read-only] nativeText : string

This property provides the shortcut's key sequence as a platform specific string. This means that it will be shown translated, and on macOS it will resemble a key sequence from the menu bar. It is best to display this text to the user (for example, on a tooltip).

See also sequence and portableText.


[read-only] portableText : string

This property provides the shortcut's key sequence as a string in a "portable" format, suitable for reading and writing to a file. In many cases, it will look similar to the native text on Windows and X11.

See also sequence and nativeText.


sequence : keysequence

This property holds the shortcut's key sequence. The key sequence can be set to one of the standard keyboard shortcuts, or it can be described with a string containing a sequence of up to four key presses that are needed to activate the shortcut.

The default value is an empty key sequence.

Shortcut {
    sequence: "Ctrl+E,Ctrl+W"
    onActivated: edit.wrapMode = TextEdit.Wrap
}

Note: Given that standard keys can resolve to one shortcut on some platforms, but multiple shortcuts on other platforms, we recommend always using sequences for standard keys.

See also sequences.


sequences : list<keysequence>

This property holds multiple key sequences for the shortcut. The key sequences can be set to one of the standard keyboard shortcuts, or they can be described with strings containing sequences of up to four key presses that are needed to activate the shortcut.

Shortcut {
    sequences: [StandardKey.Cut, "Ctrl+X", "Shift+Del"]
    onActivated: edit.cut()
}

Signal Documentation

activated()

This signal is emitted when the shortcut is activated.

Note: The corresponding handler is onActivated.


activatedAmbiguously()

This signal is emitted when the shortcut is activated ambigously, meaning that it matches the start of more than one shortcut.

Note: The corresponding handler is onActivatedAmbiguously.


© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.