summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2019-06-21 16:31:04 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2019-07-02 16:35:18 +0200
commit555661b625c40f21a6a3e4c73e928a6e8a46db20 (patch)
treec10f08ab3c19596fabfee918b5a94a6597062a79
parent1eeab2d27f61485cb53364d40339a8d832a076e9 (diff)
Update visible window's alpha when toggling WA_TranslucentBackground
QWidgetPrivate::updateIsTranslucent sets the surface format of the window with the alpha based on the translucency attribute, so we need to call this function when the attribute value changes. The test can confirm that the window's requested surface format has changed, we can't rely on what is actually set, and don't have to rely on hard-coded values like 8bit alpha. While WA_NoSystemBackground needs to be set for WA_TranslucentBackground to have an effect, we can't clear the attribute when clearing translucency (as it might have been set explicitly). Change-Id: I238d6930b7e0488397467a4e035b5f530566a1ff Fixes: QTBUG-60822 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/widgets/kernel/qwidget.cpp5
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp6
2 files changed, 8 insertions, 3 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 6ef3a4f163..50745175b4 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -11474,10 +11474,9 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
}
break;
case Qt::WA_TranslucentBackground:
- if (on) {
+ if (on)
setAttribute(Qt::WA_NoSystemBackground);
- d->updateIsTranslucent();
- }
+ d->updateIsTranslucent();
break;
case Qt::WA_AcceptTouchEvents:
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 489edb703c..7edca2017d 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -8855,6 +8855,12 @@ void tst_QWidget::translucentWidget()
QEXPECT_FAIL("", "WinRT: This fails. QTBUG-68297.", Abort);
QCOMPARE(actual.size(),expected.size());
QCOMPARE(actual,expected);
+
+ const QWindow *window = label.windowHandle();
+ const QSurfaceFormat translucentFormat = window->requestedFormat();
+ label.setAttribute(Qt::WA_TranslucentBackground, false);
+ const QSurfaceFormat opaqueFormat = window->requestedFormat();
+ QVERIFY(translucentFormat != opaqueFormat);
}
class MaskResizeTestWidget : public QWidget