Change order of menuBar/header/footer to match visual order

Currently, the tab navigation order is confusing as the footer is
focused before the actual content of the ApplicationWindow. By adjusting
the stack order, the tab navigation now matches the visual order.

Fixes: QTBUG-137823
Pick-to: 6.8 6.9 6.10
Change-Id: Ibe6fe9305181fe7ed42d7f8ca2da689b1b6ccf41
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Jan Moeller 2025-06-26 11:47:29 +02:00
parent 5935a83948
commit df2c402979
2 changed files with 59 additions and 49 deletions

View File

@ -428,6 +428,8 @@ void QQuickApplicationWindow::setHeader(QQuickItem *header)
else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(header))
buttonBox->setPosition(QQuickDialogButtonBox::Header);
#endif
header->stackBefore(d->control);
}
if (isComponentComplete())
d->relayout();
@ -484,6 +486,8 @@ void QQuickApplicationWindow::setFooter(QQuickItem *footer)
tabBar->setPosition(QQuickTabBar::Footer);
else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(footer))
buttonBox->setPosition(QQuickDialogButtonBox::Footer);
footer->stackAfter(d->control);
#endif
}
if (isComponentComplete())
@ -727,6 +731,11 @@ void QQuickApplicationWindow::setMenuBar(QQuickItem *menuBar)
p->addItemChangeListener(d, ItemChanges);
if (qFuzzyIsNull(menuBar->z()))
menuBar->setZ(2);
if (header())
menuBar->stackBefore(header());
else
menuBar->stackBefore(d->control);
}
if (isComponentComplete())
d->relayout();

View File

@ -122,29 +122,7 @@ void tst_QQuickApplicationWindow::activeFocusOnTab1()
QVERIFY(item);
QVERIFY(!item->hasActiveFocus());
// Tab: contentItem->sub1
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QGuiApplication::sendEvent(window, &key);
QVERIFY(key.isAccepted());
item = findItem<QQuickItem>(window->contentItem(), "sub1");
QVERIFY(item);
QVERIFY_ACTIVE_FOCUS(item);
}
// Tab: sub1->sub2
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QGuiApplication::sendEvent(window, &key);
QVERIFY(key.isAccepted());
item = findItem<QQuickItem>(window->contentItem(), "sub2");
QVERIFY(item);
QVERIFY_ACTIVE_FOCUS(item);
}
// Tab: sub2->menuBar
// Tab: contentItem->menuBar
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QGuiApplication::sendEvent(window, &key);
@ -166,7 +144,29 @@ void tst_QQuickApplicationWindow::activeFocusOnTab1()
QVERIFY_ACTIVE_FOCUS(item);
}
// Tab: header->footer
// Tab: header->sub1
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QGuiApplication::sendEvent(window, &key);
QVERIFY(key.isAccepted());
item = findItem<QQuickItem>(window->contentItem(), "sub1");
QVERIFY(item);
QVERIFY_ACTIVE_FOCUS(item);
}
// Tab: sub1->sub2
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QGuiApplication::sendEvent(window, &key);
QVERIFY(key.isAccepted());
item = findItem<QQuickItem>(window->contentItem(), "sub2");
QVERIFY(item);
QVERIFY_ACTIVE_FOCUS(item);
}
// Tab: sub2->footer
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QGuiApplication::sendEvent(window, &key);
@ -177,13 +177,14 @@ void tst_QQuickApplicationWindow::activeFocusOnTab1()
QVERIFY_ACTIVE_FOCUS(item);
}
// Tab: footer->sub1
// Tab: footer->menuBar
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
QGuiApplication::sendEvent(window, &key);
QVERIFY(key.isAccepted());
item = findItem<QQuickItem>(window->contentItem(), "sub1");
item = qobject_cast<QQuickApplicationWindow *>(window)->menuBar();
QVERIFY(item);
QVERIFY_ACTIVE_FOCUS(item);
}
@ -224,29 +225,7 @@ void tst_QQuickApplicationWindow::activeFocusOnTab2()
QVERIFY_ACTIVE_FOCUS(item);
}
// BackTab: footer->header
{
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
// BackTab: footer->sub2
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier);
QGuiApplication::sendEvent(window, &key);
@ -268,7 +247,29 @@ void tst_QQuickApplicationWindow::activeFocusOnTab2()
QVERIFY_ACTIVE_FOCUS(item);
}
// BackTab: sub1->footer
// BackTab: sub1->header
{
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->footer
{
QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier);
QGuiApplication::sendEvent(window, &key);