From 98fdf50c30e1c8525e1087aa88cca2c6188a9d40 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Wed, 19 Oct 2022 17:13:27 +0200 Subject: [PATCH] Set alphaBufferSize to -1 when disabling translucency in QtWidgets -1 is the default value for QSurfaceFormat::alphaBufferSize. Changing it to 0 may result an unexpected pixel format change by ARB OpenGL extension. Fixes: QTBUG-107629 Change-Id: Ia6a1b90fba6c43b6872b406f4fd946d937135cf8 Reviewed-by: Laszlo Agocs (cherry picked from commit 600752aa972d1e46792e18f1ec6dd0b519722e65) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/kernel/qwidget.cpp | 2 +- .../qopenglwidget/tst_qopenglwidget.cpp | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 93e838d8b82..361e12887a6 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2201,7 +2201,7 @@ void QWidgetPrivate::updateIsTranslucent() if (QWindow *window = q->windowHandle()) { QSurfaceFormat format = window->format(); const int oldAlpha = format.alphaBufferSize(); - const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground)? 8 : 0; + const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground) ? 8 : -1; if (oldAlpha != newAlpha) { // QTBUG-85714: Do this only when the QWindow has not yet been create()'ed yet. // diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp index f90879ab124..9d94aa5aca8 100644 --- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp +++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp @@ -47,6 +47,8 @@ private slots: void offscreen(); void offscreenThenOnscreen(); void paintWhileHidden(); + void widgetWindowColorFormat_data(); + void widgetWindowColorFormat(); #ifdef QT_BUILD_INTERNAL void staticTextDanglingPointer(); @@ -793,6 +795,30 @@ void tst_QOpenGLWidget::paintWhileHidden() QTRY_VERIFY(w->m_paintCalled > 0); } +void tst_QOpenGLWidget::widgetWindowColorFormat_data() +{ + QTest::addColumn("translucent"); + QTest::newRow("Translucent background disabled") << false; + QTest::newRow("Translucent background enabled") << true; +} + +void tst_QOpenGLWidget::widgetWindowColorFormat() +{ + QFETCH(bool, translucent); + + QOpenGLWidget w; + w.setAttribute(Qt::WA_TranslucentBackground, translucent); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + w.setFixedSize(16, 16); + w.show(); + QVERIFY(QTest::qWaitForWindowExposed(&w)); + + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + QCOMPARE(w.format().redBufferSize(), ctx->format().redBufferSize()); + QCOMPARE(w.format().greenBufferSize(), ctx->format().greenBufferSize()); + QCOMPARE(w.format().blueBufferSize(), ctx->format().blueBufferSize()); +} + class StaticTextPainterWidget : public QOpenGLWidget { public: