summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-09-23 17:40:27 +0200
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-09-24 12:51:37 +0000
commitb46ffbca0cfad41599873d4ca19dc79167c3955f (patch)
treee8176dee68e341de8efe82eb442ce883f7950957 /src/widgets
parentbf2c9fd2fdff2760f3798fd1584f2da330266c46 (diff)
Fix up QOpenGLWidget transparency support
The glColorMask call was troublesome. In addition, the Qt::WA_TranslucentBackground was misinterpreted and recommended misleadingly in the documentation. The hellogl2 example's --transparent argument was disfunctional in practice. Replace glColorMask with glBlendFuncSeparate. The hellogl2 example and the docs are now corrected wrt enabling semi-transparency in a QOpenGLWidget that is not a top-level (which is the most common case). Task-number: QTBUG-47276 Change-Id: I6f40e732d455f5efcf158649ac9a52ff9f240e85 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qopenglwidget.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp
index b98e8a6a66..92f6066936 100644
--- a/src/widgets/kernel/qopenglwidget.cpp
+++ b/src/widgets/kernel/qopenglwidget.cpp
@@ -425,7 +425,12 @@ QT_BEGIN_NAMESPACE
Note that this does not apply when there are no other widgets underneath and
the intention is to have a semi-transparent window. In that case the
- traditional approach of setting Qt::WA_TranslucentBackground is sufficient.
+ traditional approach of setting Qt::WA_TranslucentBackground
+ on the top-level window is sufficient. Note that if the transparent areas are
+ only desired in the QOpenGLWidget, then Qt::WA_NoSystemBackground will need
+ to be turned back to \c false after enabling Qt::WA_TranslucentBackground.
+ Additionally, requesting an alpha channel for the QOpenGLWidget's context via
+ setFormat() may be necessary too, depending on the system.
QOpenGLWidget supports multiple update behaviors, just like QOpenGLWindow. In
preserved mode the rendered content from the previous paintGL() call is
@@ -607,7 +612,7 @@ void QOpenGLWidgetPaintDevicePrivate::beginPaint()
// with the palette's background color.
if (w->autoFillBackground()) {
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- if (w->testAttribute(Qt::WA_TranslucentBackground)) {
+ if (w->format().hasAlpha()) {
f->glClearColor(0, 0, 0, 0);
} else {
QColor c = w->palette().brush(w->backgroundRole()).color();
@@ -955,13 +960,12 @@ QOpenGLWidget::UpdateBehavior QOpenGLWidget::updateBehavior() const
OpenGL widgets, individual calls to this function can be replaced by one single call to
QSurfaceFormat::setDefaultFormat() before creating the first widget.
- \note Requesting an alpha buffer via this function, or by setting
- Qt::WA_TranslucentBackground, will not lead to the desired results when the intention is
- to make other widgets beneath visible. Instead, use Qt::WA_AlwaysStackOnTop to enable
- semi-transparent QOpenGLWidget instances with other widgets visible underneath. Keep in
- mind however that this breaks the stacking order, so it will no longer be possible to
- have other widgets on top of the QOpenGLWidget. When the intention is to have a
- semi-transparent top-level window, Qt::WA_TranslucentBackground is sufficient.
+ \note Requesting an alpha buffer via this function will not lead to the
+ desired results when the intention is to make other widgets beneath visible.
+ Instead, use Qt::WA_AlwaysStackOnTop to enable semi-transparent QOpenGLWidget
+ instances with other widgets visible underneath. Keep in mind however that
+ this breaks the stacking order, so it will no longer be possible to have
+ other widgets on top of the QOpenGLWidget.
\sa format(), Qt::WA_AlwaysStackOnTop, QSurfaceFormat::setDefaultFormat()
*/