diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-01-06 10:26:49 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-01-25 08:10:32 +0100 |
commit | bb42b7d8b2fe8508074bc4574679893c6cf4fbd5 (patch) | |
tree | 4217bb132cd44701cdf2946033a9461994c2faf9 /tests/auto/widgets/kernel | |
parent | 236a47ff7af54f4108a2d716784b61778ef93af2 (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>
Diffstat (limited to 'tests/auto/widgets/kernel')
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
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() { |