aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-11-01 15:40:14 +0100
committerLiang Qi <liang.qi@qt.io>2018-04-11 14:08:53 +0000
commit996c6d452702162e909285b5be9a831290cff1c9 (patch)
treea3b429fb44c64ef4374f086659c4dc2e776b7926 /src
parent8780764b274217b256aadd00114a76bdffbdb1ef (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')
-rw-r--r--src/quickwidgets/qquickwidget.cpp22
-rw-r--r--src/quickwidgets/qquickwidget.h1
2 files changed, 23 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);
diff --git a/src/quickwidgets/qquickwidget.h b/src/quickwidgets/qquickwidget.h
index 3ddb0613ad..5543705f13 100644
--- a/src/quickwidgets/qquickwidget.h
+++ b/src/quickwidgets/qquickwidget.h
@@ -143,6 +143,7 @@ protected:
bool event(QEvent *) override;
void paintEvent(QPaintEvent *event) override;
+ bool focusNextPrevChild(bool next) override;
private:
Q_DISABLE_COPY(QQuickWidget)