Qt Reference Documentation

QML Keys Element

The Keys attached property provides key handling to Items. More...

  • List of all members, including inherited members
  • Properties

    Signals

    Detailed Description

    All 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.

     Item {
         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 {
         focus: true
         Keys.onLeftPressed: console.log("move left")
     }

    See Qt.Key for the list of keyboard codes.

    If priority is Keys.BeforeItem (default) the order of key event processing is:

    1. Items specified in forwardTo
    2. specific key handlers, e.g. onReturnPressed
    3. onKeyPress, onKeyRelease handlers
    4. Item specific key handling, e.g. TextInput key handling
    5. parent item

    If priority is Keys.AfterItem the order of key event processing is:

    1. Item specific key handling, e.g. TextInput key handling
    2. Items specified in forwardTo
    3. specific key handlers, e.g. onReturnPressed
    4. onKeyPress, onKeyRelease handlers
    5. parent item

    If the event is accepted during any of the above steps, key propagation stops.

    See also KeyEvent and KeyNavigation attached property.

    Property Documentation

    enabled : bool

    This flags enables key handling if true (default); otherwise no key handlers will be called.


    read-onlyforwardTo : list<Object>

    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:

     ListView { id: list1 ... }
     ListView { id: list2 ... }
     Keys.forwardTo: [list1, list2]
     focus: true

    priority : enumeration

    This property determines whether the keys are processed before or after the attached item's own key handling.

    • Keys.BeforeItem (default) - process the key events before normal item key processing. If the event is accepted it will not be passed on to the item.
    • Keys.AfterItem - process the key events after normal item key handling. If the item accepts the key event it will not be handled by the Keys attached property handler.

    Signal Documentation

    Keys::onAsteriskPressed ( event )

    This handler is called when the Asterisk '*' has been pressed. The event parameter provides information about the event.


    Keys::onBackPressed ( event )

    This handler is called when the Back key has been pressed. The event parameter provides information about the event.


    Keys::onCallPressed ( event )

    This handler is called when the Call key has been pressed. The event parameter provides information about the event.


    Keys::onCancelPressed ( event )

    This handler is called when the Cancel key has been pressed. The event parameter provides information about the event.


    Keys::onContext1Pressed ( event )

    This handler is called when the Context1 key has been pressed. The event parameter provides information about the event.


    Keys::onContext2Pressed ( event )

    This handler is called when the Context2 key has been pressed. The event parameter provides information about the event.


    Keys::onContext3Pressed ( event )

    This handler is called when the Context3 key has been pressed. The event parameter provides information about the event.


    Keys::onContext4Pressed ( event )

    This handler is called when the Context4 key has been pressed. The event parameter provides information about the event.


    Keys::onDeletePressed ( event )

    This handler is called when the Delete key has been pressed. The event parameter provides information about the event.


    Keys::onDigit0Pressed ( event )

    This handler is called when the digit '0' has been pressed. The event parameter provides information about the event.


    Keys::onDigit1Pressed ( event )

    This handler is called when the digit '1' has been pressed. The event parameter provides information about the event.


    Keys::onDigit2Pressed ( event )

    This handler is called when the digit '2' has been pressed. The event parameter provides information about the event.


    Keys::onDigit3Pressed ( event )

    This handler is called when the digit '3' has been pressed. The event parameter provides information about the event.


    Keys::onDigit4Pressed ( event )

    This handler is called when the digit '4' has been pressed. The event parameter provides information about the event.


    Keys::onDigit5Pressed ( event )

    This handler is called when the digit '5' has been pressed. The event parameter provides information about the event.


    Keys::onDigit6Pressed ( event )

    This handler is called when the digit '6' has been pressed. The event parameter provides information about the event.


    Keys::onDigit7Pressed ( event )

    This handler is called when the digit '7' has been pressed. The event parameter provides information about the event.


    Keys::onDigit8Pressed ( event )

    This handler is called when the digit '8' has been pressed. The event parameter provides information about the event.


    Keys::onDigit9Pressed ( event )

    This handler is called when the digit '9' has been pressed. The event parameter provides information about the event.


    Keys::onDownPressed ( event )

    This handler is called when the Down arrow has been pressed. The event parameter provides information about the event.


    Keys::onEnterPressed ( event )

    This handler is called when the Enter key has been pressed. The event parameter provides information about the event.


    Keys::onEscapePressed ( event )

    This handler is called when the Escape key has been pressed. The event parameter provides information about the event.


    Keys::onFlipPressed ( event )

    This handler is called when the Flip key has been pressed. The event parameter provides information about the event.


    Keys::onHangupPressed ( event )

    This handler is called when the Hangup key has been pressed. The event parameter provides information about the event.


    Keys::onLeftPressed ( event )

    This handler is called when the Left arrow has been pressed. The event parameter provides information about the event.


    Keys::onMenuPressed ( event )

    This handler is called when the Menu key has been pressed. The event parameter provides information about the event.


    Keys::onNoPressed ( event )

    This handler is called when the No key has been pressed. The event parameter provides information about the event.


    Keys::onPressed ( event )

    This handler is called when a key has been pressed. The event parameter provides information about the event.


    Keys::onReleased ( event )

    This handler is called when a key has been released. The event parameter provides information about the event.


    Keys::onReturnPressed ( event )

    This handler is called when the Return key has been pressed. The event parameter provides information about the event.


    Keys::onRightPressed ( event )

    This handler is called when the Right arrow has been pressed. The event parameter provides information about the event.


    Keys::onSelectPressed ( event )

    This handler is called when the Select key has been pressed. The event parameter provides information about the event.


    Keys::onSpacePressed ( event )

    This handler is called when the Space key has been pressed. The event parameter provides information about the event.


    Keys::onUpPressed ( event )

    This handler is called when the Up arrow has been pressed. The event parameter provides information about the event.


    Keys::onVolumeDownPressed ( event )

    This handler is called when the VolumeDown key has been pressed. The event parameter provides information about the event.


    Keys::onVolumeUpPressed ( event )

    This handler is called when the VolumeUp key has been pressed. The event parameter provides information about the event.


    Keys::onYesPressed ( event )

    This handler is called when the Yes key has been pressed. The event parameter provides information about the event.


    X

    Thank you for giving your feedback.

    Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.