Provides information about a key event. 更多...
import 语句: | import QtQuick |
For example, the following changes the Item's state property when the Enter key is pressed:
Item { focus: true Keys.onPressed: (event)=> { if (event.key == Qt.Key_Enter) state = 'ShowDetails'; } }
accepted : bool |
设置 accepted to true prevents the key event from being propagated to the item's parent.
Generally, if the item acts on the key event then it should be accepted so that ancestor items do not also respond to the same event.
count
:
int
|
This property holds the number of keys involved in this event. If KeyEvent::text is not empty, this is simply the length of the string.
isAutoRepeat
:
bool
|
This property holds whether this event comes from an auto-repeating key.
key
:
int
|
This property holds the code of the key that was pressed or released.
见 Qt.Key for the list of keyboard codes. These codes are independent of the underlying window system. Note that this function does not distinguish between capital and non-capital letters; use the text property for this purpose.
值为 0 或 Qt.Key_Unknown 意味着事件不是已知按键的结果;例如,它可能是合成序列、键盘宏、或由于键事件压缩的结果。
modifiers
:
int
|
This property holds the keyboard modifier flags that existed immediately before the event occurred.
It contains a bitwise combination of numeric values (the same as in Qt::KeyboardModifier ):
常量 | 描述 |
---|---|
Qt.NoModifier
|
未按下修饰符键。 |
Qt.ShiftModifier
|
}A Shift key on the keyboard is pressed. |
Qt.ControlModifier
|
按下键盘 Ctrl 键。 |
Qt.AltModifier
|
按下键盘 Alt 键。 |
Qt.MetaModifier
|
按下键盘 Meta 键。 |
Qt.KeypadModifier
|
按下 Keypad (小键盘) 按钮。 |
Qt.GroupSwitchModifier
|
X11 only. A Mode_switch key on the keyboard is pressed. |
For example, to react to a Shift key + Enter key combination:
Item { focus: true Keys.onPressed: (event)=> { if ((event.key == Qt.Key_Enter) && (event.modifiers & Qt.ShiftModifier)) doSomething(); } }
nativeScanCode
:
quint32
|
This property contains the native scan code of the key that was pressed. It is passed through from QKeyEvent unchanged.
另请参阅 QKeyEvent::nativeScanCode ().
text
:
string
|
This property holds the Unicode text that the key generated. The text returned can be an empty string in cases where modifier keys, such as Shift, Control, Alt, and Meta, are being pressed or released. In such cases
key
will contain a valid value
bool 匹配 ( StandardKey matchKey ) |
返回
true
若键事件匹配给定标准
matchKey
;否则返回
false
.
Item { focus: true Keys.onPressed: (event)=> { if (event.matches(StandardKey.Undo)) myModel.undo(); else if (event.matches(StandardKey.Redo)) myModel.redo(); } }
另请参阅 QKeySequence::StandardKey .