diff options
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 22 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 11 |
2 files changed, 28 insertions, 5 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 14012219f9..a5ad101201 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2191,8 +2191,26 @@ void QWidgetPrivate::updateIsTranslucent() const int oldAlpha = format.alphaBufferSize(); const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground)? 8 : 0; if (oldAlpha != newAlpha) { - format.setAlphaBufferSize(newAlpha); - window->setFormat(format); + // QTBUG-85714: Do this only when the QWindow has not yet been create()'ed yet. + // + // If that is not the case, then the setFormat() is not just futile + // but downright dangerous. Futile because the format matters only + // when creating the native window, no point in changing it + // afterwards. Dangerous because a QOpenGLContext or something else + // may eventually query the QWindow's format(), in order to ensure + // compatibility (in terms of native concepts such as pixel format, + // EGLConfig, etc.), and if we change it here, then the returned + // format does not describe reality anymore. (reality being the + // settings with which the native resource was created). + // + // Whereas if one does a destroy()-create() then this all here + // won't matter because the format is updated in + // QWidgetPrivate::create() again. + // + if (!window->handle()) { + format.setAlphaBufferSize(newAlpha); + window->setFormat(format); + } } } } diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 8992a0b051..7ca08993ab 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -9316,10 +9316,15 @@ void tst_QWidget::translucentWidget() QCOMPARE(actual,expected); const QWindow *window = label.windowHandle(); - const QSurfaceFormat translucentFormat = window->requestedFormat(); + const QSurfaceFormat translucentFormat = window->format(); label.setAttribute(Qt::WA_TranslucentBackground, false); - const QSurfaceFormat opaqueFormat = window->requestedFormat(); - QVERIFY(translucentFormat != opaqueFormat); + // Changing WA_TranslucentBackground with an already created native window + // has no effect since Qt 5.0 due to the introduction of QWindow et al. + // This means that the change must *not* be reflected in the + // QSurfaceFormat, because there is no change when it comes to the + // underlying native window. Otherwise the state would no longer + // describe reality (the native window) See QTBUG-85714. + QVERIFY(translucentFormat == window->format()); } class MaskResizeTestWidget : public QWidget |