diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-22 18:04:59 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-02-24 08:15:46 +0000 |
commit | 8a4db8ec31426a3ca2697ec868f566ba43bbe597 (patch) | |
tree | de02f6e7f325b54621eb55c0cb4485d38360c433 /src/templates | |
parent | 859663ae2971f3b6b99239dda24782eda2d88347 (diff) |
RangeSlider: forward focus to the handles
The active focus ends up to RangeSlider when using forceActiveFocus()
or QML KeyNavigation. We must forward the focus to one of the handles,
because RangeSlider handles key events for the focused handle. If
neither handle has active focus, RangeSlider doesn't do anything.
Change-Id: I61a53d0c7203fad64306b54c1f96093bd9312416
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'src/templates')
-rw-r--r-- | src/templates/qquickrangeslider.cpp | 18 | ||||
-rw-r--r-- | src/templates/qquickrangeslider_p.h | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/templates/qquickrangeslider.cpp b/src/templates/qquickrangeslider.cpp index 55b5bd8c..69529f65 100644 --- a/src/templates/qquickrangeslider.cpp +++ b/src/templates/qquickrangeslider.cpp @@ -691,6 +691,24 @@ void QQuickRangeSlider::setValues(qreal firstValue, qreal secondValue) secondPrivate->updatePosition(); } +void QQuickRangeSlider::focusInEvent(QFocusEvent *event) +{ + Q_D(QQuickRangeSlider); + QQuickControl::focusInEvent(event); + + // The active focus ends up to RangeSlider when using forceActiveFocus() + // or QML KeyNavigation. We must forward the focus to one of the handles, + // because RangeSlider handles key events for the focused handle. If + // neither handle has active focus, RangeSlider doesn't do anything. + QQuickItem *handle = nextItemInFocusChain(); + // QQuickItem::nextItemInFocusChain() only works as desired with + // Qt::TabFocusAllControls. otherwise pick the first handle + if (!handle || handle == this) + handle = d->first->handle(); + if (handle) + handle->forceActiveFocus(event->reason()); +} + void QQuickRangeSlider::keyPressEvent(QKeyEvent *event) { Q_D(QQuickRangeSlider); diff --git a/src/templates/qquickrangeslider_p.h b/src/templates/qquickrangeslider_p.h index 604666c8..4cf6ffd6 100644 --- a/src/templates/qquickrangeslider_p.h +++ b/src/templates/qquickrangeslider_p.h @@ -109,6 +109,7 @@ Q_SIGNALS: void trackChanged(); protected: + void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE; void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; |