summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-01-06 10:26:49 +0100
committerAndy Shaw <andy.shaw@qt.io>2020-01-25 08:10:32 +0100
commitbb42b7d8b2fe8508074bc4574679893c6cf4fbd5 (patch)
tree4217bb132cd44701cdf2946033a9461994c2faf9
parent236a47ff7af54f4108a2d716784b61778ef93af2 (diff)
Make sure the focus is passed on correctly when back-tabbing
When the tested widget has a focus proxy, then we should check if the current focus widget is not the same as that focus proxy before setting it to be the widget that gets focus. This ensures that when back-tabbing from a widget like QDoubleSpinBox that it will not get stuck inside that widget and will back-tab to the next correct one. Fixes: QTBUG-81097 Change-Id: I3f689c7715da7f3ce8c3d2f616041528f5778a2f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--src/widgets/kernel/qapplication.cpp3
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp28
2 files changed, 30 insertions, 1 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index ef76265f8b..ce32fd39a8 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2139,7 +2139,8 @@ QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool
&& !(!next && focusProxy && test->isAncestorOf(focusProxy))
&& test->isVisibleTo(toplevel) && test->isEnabled()
&& !(w->windowType() == Qt::SubWindow && !w->isAncestorOf(test))
- && (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))) {
+ && (toplevel->windowType() != Qt::SubWindow || toplevel->isAncestorOf(test))
+ && f != focusProxy) {
w = test;
if (seenWindow)
focusWidgetAfterWindow = true;
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 371738ad27..b5d174f340 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -72,6 +72,7 @@
#include <QtWidgets/QGraphicsProxyWidget>
#include <QtGui/qwindow.h>
#include <qtimer.h>
+#include <QtWidgets/QDoubleSpinBox>
#if defined(Q_OS_OSX)
#include "tst_qwidget_mac_helpers.h" // Abstract the ObjC stuff out so not everyone must run an ObjC++ compile.
@@ -187,6 +188,7 @@ private slots:
void tabOrderNoChange2();
void appFocusWidgetWithFocusProxyLater();
void appFocusWidgetWhenLosingFocusProxy();
+ void explicitTabOrderWithComplexWidget();
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
void activation();
#endif
@@ -2086,6 +2088,32 @@ void tst_QWidget::appFocusWidgetWhenLosingFocusProxy()
QCOMPARE(QApplication::focusWidget(), lineEdit);
}
+void tst_QWidget::explicitTabOrderWithComplexWidget()
+{
+ // Check that handling tab/backtab with a widget comprimised of other widgets
+ // handles tabbing correctly
+ Container window;
+ auto lineEditOne = new QLineEdit;
+ window.box->addWidget(lineEditOne);
+ auto lineEditTwo = new QLineEdit;
+ window.box->addWidget(lineEditTwo);
+ QWidget::setTabOrder(lineEditOne, lineEditTwo);
+ lineEditOne->setFocus();
+ window.show();
+ QApplication::setActiveWindow(&window);
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ QTRY_COMPARE(QApplication::focusWidget(), lineEditOne);
+
+ window.tab();
+ QTRY_COMPARE(QApplication::focusWidget(), lineEditTwo);
+ window.tab();
+ QTRY_COMPARE(QApplication::focusWidget(), lineEditOne);
+ window.backTab();
+ QTRY_COMPARE(QApplication::focusWidget(), lineEditTwo);
+ window.backTab();
+ QTRY_COMPARE(QApplication::focusWidget(), lineEditOne);
+}
+
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
void tst_QWidget::activation()
{