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: