Shortcut QML Type
提供键盘快捷键。更多
| Import Statement: | import QtQuick |
属性
- autoRepeat : bool
- context : enumeration
- enabled : bool
- nativeText : string
- portableText : string
- sequence : keysequence
- sequences : list<keysequence>
信号
详细说明
快捷方式类型可让您处理键盘快捷方式。快捷方式可以设置为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() }
信号文档
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.