快捷键 Ctrl+Down 实战
Shortcut Ctrl+Down in Action
我想要一个 Action
触发快捷键 Ctrl+↓.
我能做的是 ↓:
的快捷方式
Action {
shortcut: StandardKey.MoveToNextLine
enabled: true
onTriggered: console.log('Down pressed')
}
但是如何定义快捷键Ctrl+↓?
使用类似的东西:
Keys.onPressed: {
if ((event.key == Qt.Key_Down) && (event.modifiers & Qt.ControlModifier))
doSomething();
}
从 shortcut
的 documentation 你读到:
Shortcut bound to the action. The keysequence can be a string or a standard key.
从 QKeySequence
toString()
方法 documentation 你还读到:
Return a string representation of the key sequence, based on format.
For example, the value Qt::CTRL+Qt::Key_O results in "Ctrl+O". If the key sequence has multiple key codes, each is separated by commas in the string returned, such as "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are translated using QObject::tr() in the "QShortcut" context.
因此,使用键名组合而不是像这样的 StandardKey
:
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
ApplicationWindow {
id: rectangle
width: 200
height: 200
visible: true
Action {
shortcut: "Ctrl+Down"
enabled: true
onTriggered: console.log('Down pressed [ctrl hold]')
}
}
我想要一个 Action
触发快捷键 Ctrl+↓.
我能做的是 ↓:
的快捷方式Action {
shortcut: StandardKey.MoveToNextLine
enabled: true
onTriggered: console.log('Down pressed')
}
但是如何定义快捷键Ctrl+↓?
使用类似的东西:
Keys.onPressed: {
if ((event.key == Qt.Key_Down) && (event.modifiers & Qt.ControlModifier))
doSomething();
}
从 shortcut
的 documentation 你读到:
Shortcut bound to the action. The keysequence can be a string or a standard key.
从 QKeySequence
toString()
方法 documentation 你还读到:
Return a string representation of the key sequence, based on format.
For example, the value Qt::CTRL+Qt::Key_O results in "Ctrl+O". If the key sequence has multiple key codes, each is separated by commas in the string returned, such as "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are translated using QObject::tr() in the "QShortcut" context.
因此,使用键名组合而不是像这样的 StandardKey
:
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3
ApplicationWindow {
id: rectangle
width: 200
height: 200
visible: true
Action {
shortcut: "Ctrl+Down"
enabled: true
onTriggered: console.log('Down pressed [ctrl hold]')
}
}