From a623293a13c9a0c80ae4a5111b92f00ba70d1edf Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 16 Apr 2024 10:30:38 +0200 Subject: [PATCH] Baseline testing: use a full screen background behind the test window Some tests are flaky on macOS because the background desktop shows through the rounded corner of the test window. We cannot reliably control this on each platform, so instead make the test window a secondary window with a second, fullscreen and frameless window as the transient parent. This way, we have full control over the background pixels that might show through (semi-)transparent parts of the test window. Pick-to: 6.7 Change-Id: I44b7e834797b46fa8b44d776f6b91c99536a6cc9 Reviewed-by: Axel Spoerl --- tests/baseline/shared/qwidgetbaselinetest.cpp | 9 +++++++-- tests/baseline/shared/qwidgetbaselinetest.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/baseline/shared/qwidgetbaselinetest.cpp b/tests/baseline/shared/qwidgetbaselinetest.cpp index 504e5f432d3..9c642b7f48d 100644 --- a/tests/baseline/shared/qwidgetbaselinetest.cpp +++ b/tests/baseline/shared/qwidgetbaselinetest.cpp @@ -77,11 +77,14 @@ void QWidgetBaselineTest::initTestCase() void QWidgetBaselineTest::init() { QVERIFY(!window); - window = new QWidget; + background = new QWidget(nullptr, Qt::FramelessWindowHint); + window = new QWidget(background, Qt::Window); window->setWindowTitle(QTest::currentDataTag()); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + background->setScreen(QGuiApplication::primaryScreen()); window->setScreen(QGuiApplication::primaryScreen()); #endif + background->move(QGuiApplication::primaryScreen()->availableGeometry().topLeft()); window->move(QGuiApplication::primaryScreen()->availableGeometry().topLeft()); doInit(); @@ -91,13 +94,15 @@ void QWidgetBaselineTest::cleanup() { doCleanup(); - delete window; + delete background; + background = nullptr; window = nullptr; } void QWidgetBaselineTest::makeVisible() { Q_ASSERT(window); + background->showMaximized(); window->show(); QApplicationPrivate::setActiveWindow(window); QVERIFY(QTest::qWaitForWindowActive(window)); diff --git a/tests/baseline/shared/qwidgetbaselinetest.h b/tests/baseline/shared/qwidgetbaselinetest.h index 355d7d75a0b..2142217c09a 100644 --- a/tests/baseline/shared/qwidgetbaselinetest.h +++ b/tests/baseline/shared/qwidgetbaselinetest.h @@ -35,6 +35,7 @@ protected: QImage takeScreenSnapshot(const QRect& rect = QRect()); private: + QWidget *background = nullptr; QWidget *window = nullptr; };