diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-08-24 22:56:45 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-08-30 04:25:22 +0000 |
commit | 81e298a51d08c510457b4a26b37c0d4aac5eba65 (patch) | |
tree | d3278e9d2c62b794aff6fe1fd6aadb05c5b05268 /tests/auto/widgets | |
parent | 9a3bdbf40af7e4915ed343c8e9917a0f3f54e0ae (diff) |
QWidget: fix setTabOrder for compound widgets
When adjusting the tab order for compound widgets, it can happen that
the order is already correct. The check for this case forgot one case
which lead to a garbled focus chain.
Task-number: QTBUG-68393
Task-number: QTBUG-69619
Task-number: QTBUG-10907
Change-Id: Ic3242746bdcf3a4db6ea8daa1498381500ca116d
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index ae50b32164..360e6986f6 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -188,6 +188,7 @@ private slots: void reverseTabOrder(); void tabOrderWithProxy(); void tabOrderWithCompoundWidgets(); + void tabOrderNoChange(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void activation(); #endif @@ -1930,6 +1931,34 @@ void tst_QWidget::tabOrderWithCompoundWidgets() QVERIFY(lastEdit->hasFocus()); } +static QVector<QWidget*> getFocusChain(QWidget *start, bool bForward) +{ + QVector<QWidget*> ret; + QWidget *cur = start; + do { + ret += cur; + auto widgetPrivate = static_cast<QWidgetPrivate *>(qt_widget_private(cur)); + cur = bForward ? widgetPrivate->focus_next : widgetPrivate->focus_prev; + } while (cur != start); + return ret; +} + +void tst_QWidget::tabOrderNoChange() +{ + QWidget w; + auto *verticalLayout = new QVBoxLayout(&w); + auto *tabWidget = new QTabWidget(&w); + auto *tv = new QTreeView(tabWidget); + tabWidget->addTab(tv, QStringLiteral("Tab 1")); + verticalLayout->addWidget(tabWidget); + + const auto focusChainForward = getFocusChain(&w, true); + const auto focusChainBackward = getFocusChain(&w, false); + QWidget::setTabOrder(tabWidget, tv); + QCOMPARE(focusChainForward, getFocusChain(&w, true)); + QCOMPARE(focusChainBackward, getFocusChain(&w, false)); +} + #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void tst_QWidget::activation() { |