diff options
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeevents.cpp | 21 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitem.cpp | 43 |
2 files changed, 34 insertions, 30 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeevents.cpp b/src/declarative/graphicsitems/qdeclarativeevents.cpp index dbfb3fb..61fd562 100644 --- a/src/declarative/graphicsitems/qdeclarativeevents.cpp +++ b/src/declarative/graphicsitems/qdeclarativeevents.cpp @@ -113,11 +113,13 @@ Item { \qmlclass MouseEvent QDeclarativeMouseEvent \since 4.7 \ingroup qml-event-elements - + \brief The MouseEvent object provides information about a mouse event. - The position of the mouse can be found via the x and y properties. - The button that caused the event is available via the button property. + The position of the mouse can be found via the \l x and \l y properties. + The button that caused the event is available via the \l button property. + + \sa MouseArea */ /*! @@ -129,7 +131,7 @@ Item { \qmlproperty int MouseEvent::x \qmlproperty int MouseEvent::y - These properties hold the position of the mouse event. + These properties hold the coordinates of the position supplied by the mouse event. */ @@ -186,7 +188,7 @@ Item { It contains a bitwise combination of: \list \o Qt.NoModifier - No modifier key is pressed. - \o Qt.ShiftModifier - A Shift key on the keyboard is pressed. + \o Qt.ShiftModifier - A Shift key on the keyboard is pressed. \o Qt.ControlModifier - A Ctrl key on the keyboard is pressed. \o Qt.AltModifier - An Alt key on the keyboard is pressed. \o Qt.MetaModifier - A Meta key on the keyboard is pressed. @@ -195,9 +197,12 @@ Item { For example, to react to a Shift key + Left mouse button click: \qml -MouseArea { - onClicked: { if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier) doSomething(); } -} + MouseArea { + onClicked: { + if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier) + doSomething(); + } + } \endqml */ diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index 51eb5f2..95a4fd6 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -728,41 +728,39 @@ void QDeclarativeKeyNavigationAttached::keyReleased(QKeyEvent *event, bool post) \since 4.7 \brief The Keys attached property provides key handling to Items. - All visual primitives support key handling via the \e Keys - attached property. Keys can be handled via the \e onPressed - and \e onReleased signal properties. + 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 \l KeyEvent parameter, named \e event which contains details of the event. If a key is handled \e event.accepted should be set to true to prevent the event from propagating up the item hierarchy. - \code - Item { - focus: true - Keys.onPressed: { - if (event.key == Qt.Key_Left) { - console.log("move left"); - event.accepted = true; - } - } - } - \endcode + \section1 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: + + \snippet doc/src/snippets/declarative/keys/keys-pressed.qml key item Some keys may alternatively be handled via specific signal properties, for example \e onSelectPressed. These handlers automatically set \e event.accepted to true. - \code - Item { - focus: true - Keys.onLeftPressed: console.log("move left") - } - \endcode + \snippet doc/src/snippets/declarative/keys/keys-handler.qml key item + + See \l{Qt::Key}{Qt.Key} for the list of keyboard codes. - See \l {Qt::Key}{Qt.Key} for the list of keyboard codes. + \section1 Key Handling Priorities - If priority is Keys.BeforeItem (default) the order of key event processing is: + 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 \l priority is Keys.BeforeItem (default) the order of key event processing is: \list 1 \o Items specified in \c forwardTo @@ -773,6 +771,7 @@ void QDeclarativeKeyNavigationAttached::keyReleased(QKeyEvent *event, bool post) \endlist If priority is Keys.AfterItem the order of key event processing is: + \list 1 \o Item specific key handling, e.g. TextInput key handling \o Items specified in \c forwardTo |