QML Keys ElementThe Keys attached property provides key handling to Items. More... This element was introduced in Qt 4.7. PropertiesSignals
Detailed DescriptionAll visual primitives support key handling via the Keys attached property. Keys can be handled via the onPressed and onReleased signal properties. The signal properties have a KeyEvent parameter, named event which contains details of the event. If a key is handled event.accepted should be set to true to prevent the event from propagating up the item hierarchy. Example UsageThe following example shows how the general onPressed handler can be used to test for a certain key; in this case, the left cursor key: Item { anchors.fill: parent focus: true Keys.onPressed: { if (event.key == Qt.Key_Left) { console.log("move left"); event.accepted = true; } } } Some keys may alternatively be handled via specific signal properties, for example onSelectPressed. These handlers automatically set event.accepted to true. Item { anchors.fill: parent focus: true Keys.onLeftPressed: console.log("move left") } See Qt.Key for the list of keyboard codes. Key Handling PrioritiesThe Keys attached property can be configured to handle key events before or after the item it is attached to. This makes it possible to intercept events in order to override an item's default behavior, or act as a fallback for keys not handled by the item. If priority is Keys.BeforeItem (default) the order of key event processing is:
If priority is Keys.AfterItem the order of key event processing is:
If the event is accepted during any of the above steps, key propagation stops. See also KeyEvent and KeyNavigation attached property. Property DocumentationThis flags enables key handling if true (default); otherwise no key handlers will be called. This property provides a way to forward key presses, key releases, and keyboard input coming from input methods to other items. This can be useful when you want one item to handle some keys (e.g. the up and down arrow keys), and another item to handle other keys (e.g. the left and right arrow keys). Once an item that has been forwarded keys accepts the event it is no longer forwarded to items later in the list. This example forwards key events to two lists: Item { ListView { id: list1 // ... } ListView { id: list2 // ... } Keys.forwardTo: [list1, list2] focus: true } This property determines whether the keys are processed before or after the attached item's own key handling.
Signal DocumentationThis handler is called when the Asterisk '*' has been pressed. The event parameter provides information about the event. This handler is called when the Back key has been pressed. The event parameter provides information about the event. This handler is called when the Shift+Tab key combination (Backtab) has been pressed. The event parameter provides information about the event. This handler is called when the Call key has been pressed. The event parameter provides information about the event. This handler is called when the Cancel key has been pressed. The event parameter provides information about the event. This handler is called when the Context1 key has been pressed. The event parameter provides information about the event. This handler is called when the Context2 key has been pressed. The event parameter provides information about the event. This handler is called when the Context3 key has been pressed. The event parameter provides information about the event. This handler is called when the Context4 key has been pressed. The event parameter provides information about the event. This handler is called when the Delete key has been pressed. The event parameter provides information about the event. This handler is called when the digit '0' has been pressed. The event parameter provides information about the event. This handler is called when the digit '1' has been pressed. The event parameter provides information about the event. This handler is called when the digit '2' has been pressed. The event parameter provides information about the event. This handler is called when the digit '3' has been pressed. The event parameter provides information about the event. This handler is called when the digit '4' has been pressed. The event parameter provides information about the event. This handler is called when the digit '5' has been pressed. The event parameter provides information about the event. This handler is called when the digit '6' has been pressed. The event parameter provides information about the event. This handler is called when the digit '7' has been pressed. The event parameter provides information about the event. This handler is called when the digit '8' has been pressed. The event parameter provides information about the event. This handler is called when the digit '9' has been pressed. The event parameter provides information about the event. This handler is called when the Down arrow has been pressed. The event parameter provides information about the event. This handler is called when the Enter key has been pressed. The event parameter provides information about the event. This handler is called when the Escape key has been pressed. The event parameter provides information about the event. This handler is called when the Flip key has been pressed. The event parameter provides information about the event. This handler is called when the Hangup key has been pressed. The event parameter provides information about the event. This handler is called when the Left arrow has been pressed. The event parameter provides information about the event. This handler is called when the Menu key has been pressed. The event parameter provides information about the event. This handler is called when the No key has been pressed. The event parameter provides information about the event. This handler is called when a key has been pressed. The event parameter provides information about the event. This handler is called when a key has been released. The event parameter provides information about the event. This handler is called when the Return key has been pressed. The event parameter provides information about the event. This handler is called when the Right arrow has been pressed. The event parameter provides information about the event. This handler is called when the Select key has been pressed. The event parameter provides information about the event. This handler is called when the Space key has been pressed. The event parameter provides information about the event. This handler is called when the Tab key has been pressed. The event parameter provides information about the event. This handler is called when the Up arrow has been pressed. The event parameter provides information about the event. This handler is called when the VolumeDown key has been pressed. The event parameter provides information about the event. This handler is called when the VolumeUp key has been pressed. The event parameter provides information about the event. This handler is called when the Yes key has been pressed. The event parameter provides information about the event. |