diff options
author | Jan Moeller <[email protected]> | 2025-06-26 11:26:43 +0200 |
---|---|---|
committer | Jan Moeller <[email protected]> | 2025-07-01 08:20:00 +0200 |
commit | ad17c15c183f074a88fe25186c29aa937363f09f (patch) | |
tree | 04e9caaae6d870d04dcdce983f1eded184b95222 | |
parent | 2ed569070e41b5713108fe47639cf4879cb3cb11 (diff) |
To test (show) the current tab order behavior, the ApplicationWindow
of the autotest is extended by setting the menuBar, header, and
footer properties. Consequently, the autotest will now test the tab
order by traversing all the ApplicationWindow's content. Additionally
the test now ensures correct z-stacking of the contents.
Cleanup QKeyEvent creation lines by removing redundant parameters and
use consistent assignment syntax.
Fixes: QTBUG-137823
Pick-to: 6.8 6.9 6.10
Change-Id: I156397c00c308e2abd5e1f0acefd4889330f7619
Reviewed-by: Mitch Curtis <[email protected]>
-rw-r--r-- | tests/auto/quickcontrols/qquickapplicationwindow/data/activefocusontab.qml | 17 | ||||
-rw-r--r-- | tests/auto/quickcontrols/qquickapplicationwindow/tst_qquickapplicationwindow.cpp | 117 |
2 files changed, 123 insertions, 11 deletions
diff --git a/tests/auto/quickcontrols/qquickapplicationwindow/data/activefocusontab.qml b/tests/auto/quickcontrols/qquickapplicationwindow/data/activefocusontab.qml index dd53faf537..d292c8d89c 100644 --- a/tests/auto/quickcontrols/qquickapplicationwindow/data/activefocusontab.qml +++ b/tests/auto/quickcontrols/qquickapplicationwindow/data/activefocusontab.qml @@ -7,7 +7,7 @@ import QtQuick.Controls ApplicationWindow { title: "Test Application Window" width: 100 - height: 100 + height: 175 Item { id: main objectName: "main" @@ -44,4 +44,19 @@ ApplicationWindow { } } } + footer: Item { + width: 100 + height: 25 + activeFocusOnTab: true + } + header: Item { + width: 100 + height: 25 + activeFocusOnTab: true + } + menuBar: Item { + width: 100 + height: 25 + activeFocusOnTab: true + } } diff --git a/tests/auto/quickcontrols/qquickapplicationwindow/tst_qquickapplicationwindow.cpp b/tests/auto/quickcontrols/qquickapplicationwindow/tst_qquickapplicationwindow.cpp index 531e1e5ac4..92dbdd5e5e 100644 --- a/tests/auto/quickcontrols/qquickapplicationwindow/tst_qquickapplicationwindow.cpp +++ b/tests/auto/quickcontrols/qquickapplicationwindow/tst_qquickapplicationwindow.cpp @@ -59,6 +59,7 @@ private slots: void backgroundSize(); void explicitBackgroundSizeBinding(); void safeArea(); + void paintOrderChildItems(); #if QT_CONFIG(quicktemplates2_hover) void hoverInBackground(); #endif @@ -123,7 +124,7 @@ void tst_QQuickApplicationWindow::activeFocusOnTab1() // Tab: contentItem->sub1 { - QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); @@ -134,7 +135,7 @@ void tst_QQuickApplicationWindow::activeFocusOnTab1() // Tab: sub1->sub2 { - QKeyEvent key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); @@ -143,9 +144,42 @@ void tst_QQuickApplicationWindow::activeFocusOnTab1() QVERIFY_ACTIVE_FOCUS(item); } - // Tab: sub2->sub1 + // Tab: sub2->menuBar { - QKeyEvent key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "", false, 1); + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = qobject_cast<QQuickApplicationWindow *>(window)->menuBar(); + QVERIFY(item); + QVERIFY_ACTIVE_FOCUS(item); + } + + // Tab: menuBar->header + { + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = qobject_cast<QQuickApplicationWindow *>(window)->header(); + QVERIFY(item); + QVERIFY_ACTIVE_FOCUS(item); + } + + // Tab: header->footer + { + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = qobject_cast<QQuickApplicationWindow *>(window)->footer(); + QVERIFY(item); + QVERIFY_ACTIVE_FOCUS(item); + } + + // Tab: footer->sub1 + { + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); @@ -179,9 +213,42 @@ void tst_QQuickApplicationWindow::activeFocusOnTab2() QVERIFY(item); QVERIFY(!item->hasActiveFocus()); - // BackTab: contentItem->sub2 + // BackTab: contentItem->footer + { + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = qobject_cast<QQuickApplicationWindow *>(window)->footer(); + QVERIFY(item); + QVERIFY_ACTIVE_FOCUS(item); + } + + // BackTab: footer->header { - QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = qobject_cast<QQuickApplicationWindow *>(window)->header(); + QVERIFY(item); + QVERIFY_ACTIVE_FOCUS(item); + } + + // BackTab: header->menuBar + { + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier); + QGuiApplication::sendEvent(window, &key); + QVERIFY(key.isAccepted()); + + item = qobject_cast<QQuickApplicationWindow *>(window)->menuBar(); + QVERIFY(item); + QVERIFY_ACTIVE_FOCUS(item); + } + + // BackTab: menuBar->sub2 + { + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); @@ -192,7 +259,7 @@ void tst_QQuickApplicationWindow::activeFocusOnTab2() // BackTab: sub2->sub1 { - QKeyEvent key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); @@ -201,13 +268,13 @@ void tst_QQuickApplicationWindow::activeFocusOnTab2() QVERIFY_ACTIVE_FOCUS(item); } - // BackTab: sub1->sub2 + // BackTab: sub1->footer { - QKeyEvent key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); + QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); - item = findItem<QQuickItem>(window->contentItem(), "sub2"); + item = qobject_cast<QQuickApplicationWindow *>(window)->footer(); QVERIFY(item); QVERIFY_ACTIVE_FOCUS(item); } @@ -1080,6 +1147,36 @@ void tst_QQuickApplicationWindow::safeArea() } +void tst_QQuickApplicationWindow::paintOrderChildItems() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("activefocusontab.qml")); + QObject *created = component.create(); + QScopedPointer<QObject> cleanup(created); + QVERIFY(created); + + QQuickWindow *window = qobject_cast<QQuickWindow *>(created); + QVERIFY(window); + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + const auto &paintOrder = QQuickItemPrivate::get(window->contentItem())->paintOrderChildItems(); + for (const auto &child : paintOrder) { + if (child == window->contentItem()) + QVERIFY(child->z() == 0); + else if (child == qobject_cast<QQuickApplicationWindow *>(window)->menuBar()) + QVERIFY(child->z() == 2); + else if (child == qobject_cast<QQuickApplicationWindow *>(window)->header()) + QVERIFY(child->z() == 1); + else if (child == qobject_cast<QQuickApplicationWindow *>(window)->footer()) + QVERIFY(child->z() == 1); + else if (child == qobject_cast<QQuickApplicationWindow *>(window)->background()) + QVERIFY(child->z() == -1); + } +} + #if QT_CONFIG(quicktemplates2_hover) void tst_QQuickApplicationWindow::hoverInBackground() { |