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 <laszlo.agocs@qt.io>
(cherry picked from commit 600752aa972d1e46792e18f1ec6dd0b519722e65)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Peter Varga 2022-10-19 17:13:27 +02:00 committed by Qt Cherry-pick Bot
parent 81252ea92a
commit 98fdf50c30
2 changed files with 27 additions and 1 deletions

View File

@ -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.
//

View File

@ -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<bool>("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: