Shortcut QML Type

提供键盘快捷键。更多

Import Statement: import QtQuick

属性

信号

详细说明

快捷方式类型可让您处理键盘快捷方式。快捷方式可以设置为standard keyboard shortcuts ,也可以用一个字符串来描述,该字符串包含最多四个按键序列,按下这些序列即可activate 快捷方式。

Item {
    id: view

    property int currentIndex

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

也可以设置多个快捷方式sequences ,这样就可以通过几个不同的按键序列来activated 快捷方式。

另请参阅 KeysshortcutOverride()。

属性 文档

autoRepeat : bool

该属性表示快捷方式是否可以自动重复。

默认值为true


context : enumeration

该属性表示shortcut context

支持的值有

常量说明
Qt.WindowShortcut(默认)当父项目位于活动的顶层窗口中时,快捷方式处于活动状态。
Qt.ApplicationShortcut当应用程序的一个窗口处于活动状态时,快捷方式处于活动状态。
Shortcut {
    sequence: StandardKey.Quit
    context: Qt.ApplicationShortcut
    onActivated: Qt.quit()
}

enabled : bool

该属性表示快捷方式是否启用。

默认值为true


nativeText : string [read-only]

该属性以特定平台字符串的形式提供快捷方式的键序。这意味着它将被翻译显示,而在 macOS 上,它将类似于菜单栏中的键序。最好将此文本显示给用户(例如,在工具提示中)。

另请参阅 sequenceportableText


portableText : string [read-only]

该属性以 "可移植 "格式字符串提供快捷键的按键顺序,适合读写到文件中。在许多情况下,它看起来与 Windows 和 X11 上的本地文本相似。

另请参阅 sequencenativeText


sequence : keysequence

该属性包含快捷方式的键序。按键序列可以设置为standard keyboard shortcuts ,也可以用一个字符串来描述,该字符串包含最多四个按键序列,这些按键序列是activate 快捷方式所必需的。

默认值为空按键序列。

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

注意: 鉴于标准键在某些平台上可以解析为一个快捷方式,而在其他平台上则可以解析为多个快捷方式,我们建议标准键始终使用sequences

另请参见 sequences


sequences : list<keysequence>

此属性可为快捷键保留多个按键序列。按键序列可以设置为standard keyboard shortcuts 中的一个,也可以用包含最多四个按键序列的字符串来描述,这些字符串是activate 快捷键所必需的。

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

信号文档

activated()

该信号在快捷键激活时发出。

注: 相应的处理程序是onActivated


activatedAmbiguously()

该信号在快捷方式被模棱两可地激活时发出,即它与多个快捷方式的开始相匹配。

注: 相应的处理程序是onActivatedAmbiguously


© 2025 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.