Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QML Keys Element

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

This element was introduced in Qt 4.7.

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.

Example Usage

The 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 Priorities

The 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:

  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:

 Item {
     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 ( KeyEvent event )

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


Keys::onBackPressed ( KeyEvent event )

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


Keys::onBacktabPressed ( KeyEvent event )

This handler is called when the Shift+Tab key combination (Backtab) has been pressed. The event parameter provides information about the event.


Keys::onCallPressed ( KeyEvent event )

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


Keys::onCancelPressed ( KeyEvent event )

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


Keys::onContext1Pressed ( KeyEvent event )

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


Keys::onContext2Pressed ( KeyEvent event )

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


Keys::onContext3Pressed ( KeyEvent event )

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


Keys::onContext4Pressed ( KeyEvent event )

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


Keys::onDeletePressed ( KeyEvent event )

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


Keys::onDigit0Pressed ( KeyEvent event )

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


Keys::onDigit1Pressed ( KeyEvent event )

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


Keys::onDigit2Pressed ( KeyEvent event )

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


Keys::onDigit3Pressed ( KeyEvent event )

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


Keys::onDigit4Pressed ( KeyEvent event )

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


Keys::onDigit5Pressed ( KeyEvent event )

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


Keys::onDigit6Pressed ( KeyEvent event )

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


Keys::onDigit7Pressed ( KeyEvent event )

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


Keys::onDigit8Pressed ( KeyEvent event )

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


Keys::onDigit9Pressed ( KeyEvent event )

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


Keys::onDownPressed ( KeyEvent event )

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


Keys::onEnterPressed ( KeyEvent event )

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


Keys::onEscapePressed ( KeyEvent event )

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


Keys::onFlipPressed ( KeyEvent event )

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


Keys::onHangupPressed ( KeyEvent event )

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


Keys::onLeftPressed ( KeyEvent event )

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


Keys::onMenuPressed ( KeyEvent event )

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


Keys::onNoPressed ( KeyEvent event )

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


Keys::onPressed ( KeyEvent event )

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


Keys::onReleased ( KeyEvent event )

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


Keys::onReturnPressed ( KeyEvent event )

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


Keys::onRightPressed ( KeyEvent event )

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


Keys::onSelectPressed ( KeyEvent event )

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


Keys::onSpacePressed ( KeyEvent event )

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


Keys::onTabPressed ( KeyEvent event )

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


Keys::onUpPressed ( KeyEvent event )

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


Keys::onVolumeDownPressed ( KeyEvent event )

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


Keys::onVolumeUpPressed ( KeyEvent event )

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


Keys::onYesPressed ( KeyEvent event )

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


Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 44
  2. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web