summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorZhang Yu <zhangyub@uniontech.com>2021-11-30 11:14:05 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-12-02 05:45:10 +0000
commitbabb05c3dada87252066d2e0655878a66baacf48 (patch)
treee5f084d047ff9c0423f2f04cba02b18ec4a474e8 /tests
parentd6fc6a06f01a85897c0eae91f3331b68311b4a5f (diff)
Fix fail to activate first sub window with QMdiArea::TabbedView
The first sub window added will activate itself automatically, and isActive is set to true. Therefore the call to setActiveSubWindow to activate the first sub window will be ignored. When showing the mdiarea, all sub windows will be activated in the order in which they were added, so the active window will always be the last sub window added. Fix this by setting isActive to false so that setActiveSubWindow activates the first sub window when the mdiarea becomes active. Fixes: QTBUG-92037 Change-Id: Id4a793e2059803c1a4ada916fdae2d3cc02cdf06 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit c6c039167cfdbc28351a73cc0819461c69bc0451) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
index 225b349f08..55ac17ac70 100644
--- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
+++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
@@ -283,6 +283,9 @@ private slots:
void task_236750();
void qtbug92240_title_data();
void qtbug92240_title();
+ void tabbedview_activefirst();
+ void tabbedview_activesecond();
+ void tabbedview_activethird();
private:
QMdiSubWindow *activeWindow;
@@ -2738,6 +2741,60 @@ void tst_QMdiArea::qtbug92240_title()
QTRY_COMPARE(w.windowTitle(), QLatin1String("QTBUG-92240 - [2]"));
}
+static void setupMdiAreaWithTabbedView(QMdiArea &mdiArea)
+{
+ mdiArea.setViewMode(QMdiArea::TabbedView);
+
+ auto *mdiWin1 = new QWidget(&mdiArea);
+ mdiWin1->setWindowTitle(QLatin1String("Sub1"));
+ mdiArea.addSubWindow(mdiWin1);
+
+ auto *mdiWin2 = new QWidget(&mdiArea);
+ mdiWin2->setWindowTitle(QLatin1String("Sub2"));
+ mdiArea.addSubWindow(mdiWin2);
+
+ auto *mdiWin3 = new QWidget(&mdiArea);
+ mdiWin3->setWindowTitle(QLatin1String("Sub3"));
+ mdiArea.addSubWindow(mdiWin3);
+}
+
+void tst_QMdiArea::tabbedview_activefirst()
+{
+ QMdiArea mdiArea;
+ setupMdiAreaWithTabbedView(mdiArea);
+
+ auto sub0 = mdiArea.subWindowList().at(0);
+ mdiArea.setActiveSubWindow(sub0);
+ mdiArea.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&mdiArea));
+ QCOMPARE(mdiArea.activeSubWindow(), sub0);
+}
+
+void tst_QMdiArea::tabbedview_activesecond()
+{
+ QMdiArea mdiArea;
+ setupMdiAreaWithTabbedView(mdiArea);
+
+ auto sub1 = mdiArea.subWindowList().at(1);
+ mdiArea.setActiveSubWindow(sub1);
+ mdiArea.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&mdiArea));
+ QCOMPARE(mdiArea.activeSubWindow(), sub1);
+}
+
+void tst_QMdiArea::tabbedview_activethird()
+{
+ QMdiArea mdiArea;
+ setupMdiAreaWithTabbedView(mdiArea);
+
+ auto sub2 = mdiArea.subWindowList().at(2);
+ mdiArea.setActiveSubWindow(sub2);
+ mdiArea.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&mdiArea));
+ QCOMPARE(mdiArea.activeSubWindow(), sub2);
+}
+
+
QTEST_MAIN(tst_QMdiArea)
#include "tst_qmdiarea.moc"