本页内容

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 该快捷键。

另请参阅 Keys 和shortcutOverride()。

属性文档

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 上,其显示效果将类似于菜单栏中的快捷键序列。建议将此文本展示给用户(例如,在工具提示中)。

注意:如果 设置了多个键盘快捷键序列,该属性仅显示第一个序列的表示形式。

另请参阅 sequence 和portableText 。

portableText : string [read-only]

该属性以“可移植”格式的字符串形式提供快捷键序列,适合读写到文件中。在许多情况下,其显示效果与 Windows 和 X11 中的原生文本相似。

注意:如果 设置了多个键序列,此属性仅提供第一个键序列的表示形式。

另请参阅 sequence 和nativeText 。

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()
}

Signal 文档

activated()

当快捷方式被触发时,会发出此信号。

注意: 相应的处理程序 为onActivated 。

activatedAmbiguously()

当快捷键被模糊触发时(即其与多个快捷键的开头均匹配),会发出此信号。

注意: 对应的处理程序 为onActivatedAmbiguously 。

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