From b46ffbca0cfad41599873d4ca19dc79167c3955f Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 23 Sep 2015 17:40:27 +0200 Subject: 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 Reviewed-by: Gunnar Sletta --- src/widgets/kernel/qopenglwidget.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/widgets/kernel/qopenglwidget.cpp') 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() */ -- cgit v1.2.3