diff options
author | Andy Shaw <andy.shaw@qt.io> | 2017-11-01 15:40:14 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2018-04-11 14:08:53 +0000 |
commit | 996c6d452702162e909285b5be9a831290cff1c9 (patch) | |
tree | a3b429fb44c64ef4374f086659c4dc2e776b7926 /src/quickwidgets/qquickwidget.cpp | |
parent | 8780764b274217b256aadd00114a76bdffbdb1ef (diff) |
Pass on tab presses to the offscreen window to handle first
When pressing tab/backtab then the offscreen window needs to pass it on
to the item in case it will handle this for changing focus. If it does
not handle the event, it will pass it back for QWidget handling.
[ChangeLog][QQuickWidget] Tab presses are now passed on to the root
item to be handled first. When not handled by the root item, it will
be handled like a standard QWidget.
Task-number: QTBUG-45641
Change-Id: Ief0552ba496c87ab0b6e12aa8e67ef44b5a20ae2
Reviewed-by: Liang Qi <liang.qi@qt.io>
Diffstat (limited to 'src/quickwidgets/qquickwidget.cpp')
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 6f3b685974..920b400eac 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -485,6 +485,12 @@ QImage QQuickWidgetPrivate::grabFramebuffer() compatible however and attempting to construct a QQuickWidget will lead to problems. + \section1 Tab Key Handling + + On press of the \c[TAB] key, the item inside the QQuickWidget gets focus. If + this item can handle \c[TAB] key press, focus will change accordingly within + the item, otherwise the next widget in the focus chain gets focus. + \sa {Exposing Attributes of C++ Types to QML}, {Qt Quick Widgets Example}, QQuickView */ @@ -1222,6 +1228,22 @@ void QQuickWidget::resizeEvent(QResizeEvent *e) } /*! \reimp */ +bool QQuickWidget::focusNextPrevChild(bool next) +{ + Q_D(QQuickWidget); + QKeyEvent event(QEvent::KeyPress, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyPress, event.key(), + Qt::NoModifier); + QCoreApplication::sendEvent(d->offscreenWindow, &event); + + QKeyEvent releaseEvent(QEvent::KeyRelease, next ? Qt::Key_Tab : Qt::Key_Backtab, Qt::NoModifier); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyRelease, releaseEvent.key(), + Qt::NoModifier); + QCoreApplication::sendEvent(d->offscreenWindow, &releaseEvent); + return event.isAccepted(); +} + +/*! \reimp */ void QQuickWidget::keyPressEvent(QKeyEvent *e) { Q_D(QQuickWidget); |