diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 2978893205..79b83453ac 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -2376,6 +2376,11 @@ void QMdiArea::showEvent(QShowEvent *showEvent) for (QMdiSubWindow *window : copy) { if (!window) continue; + if (d->viewMode == TabbedView && window->d_func()->isActive && !d->active) { + d->showActiveWindowMaximized = true; + d->emitWindowActivated(window); // Also maximizes the window + continue; + } if (!window->testAttribute(Qt::WA_Resized)) { QSize newSize(window->sizeHint().boundedTo(viewport()->size())); window->resize(newSize.expandedTo(qSmartMinSize(window))); diff --git a/src/widgets/widgets/qmdisubwindow.h b/src/widgets/widgets/qmdisubwindow.h index a34c0249ec..4227f02dac 100644 --- a/src/widgets/widgets/qmdisubwindow.h +++ b/src/widgets/widgets/qmdisubwindow.h @@ -101,6 +101,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_enterInteractiveMode()) Q_PRIVATE_SLOT(d_func(), void _q_processFocusChanged(QWidget *, QWidget *)) friend class QMdiAreaPrivate; + friend class QMdiArea; #if QT_CONFIG(tabbar) friend class QMdiAreaTabBar; #endif diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index 1aa99f27cf..af604372ea 100644 --- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp @@ -260,6 +260,7 @@ private slots: void task_236750(); void qtbug92240_title_data(); void qtbug92240_title(); + void tabbedview_singleSubWindow(); void tabbedview_activefirst(); void tabbedview_activesecond(); void tabbedview_activethird(); @@ -2728,6 +2729,21 @@ void tst_QMdiArea::qtbug92240_title() QTRY_COMPARE(w.windowTitle(), QLatin1String("QTBUG-92240 - [2]")); } +void tst_QMdiArea::tabbedview_singleSubWindow() +{ + // With only one sub-window, setViewMode() before addSubWindow(); and addSubWindow() + // before show(), ensure the sub-window is properly activated. + QMdiArea mdiArea; + mdiArea.setViewMode(QMdiArea::TabbedView); + auto *w = new QWidget(&mdiArea); + mdiArea.addSubWindow(w); + mdiArea.show(); + QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); + auto *sub = mdiArea.subWindowList().at(0); + QCOMPARE(mdiArea.activeSubWindow(), sub); + QVERIFY(sub->isMaximized()); +} + static void setupMdiAreaWithTabbedView(QMdiArea &mdiArea) { mdiArea.setViewMode(QMdiArea::TabbedView);