From 1ea73bc29b7542141bfcfa138cc194404c283bd5 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 10 Mar 2022 15:14:43 +0100 Subject: [PATCH] Fix losing QOpenGLWidget paints when a child widget is invisible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pick-to: 6.3 6.2 Change-Id: I136b486d30e31acadd6b1b837dc7e834ee3e23fb Fixes: QTBUG-101620 Reviewed-by: Qt CI Bot Reviewed-by: Christian Strømme --- src/widgets/kernel/qwidget.cpp | 7 ++++++ .../qopenglwidget/tst_qopenglwidget.cpp | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 1527ec679f..3918a46da4 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -11049,6 +11049,13 @@ void QWidgetPrivate::update(T r) { Q_Q(QWidget); +#ifndef QT_NO_OPENGL + if (renderToTexture && !q->isVisible()) { + renderToTextureReallyDirty = 1; + return; + } +#endif + if (!q->isVisible() || !q->updatesEnabled()) return; diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp index 3d7bb36f24..12ea9e6eef 100644 --- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp +++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp @@ -66,6 +66,7 @@ private slots: void stackWidgetOpaqueChildIsVisible(); void offscreen(); void offscreenThenOnscreen(); + void paintWhileHidden(); #ifdef QT_BUILD_INTERNAL void staticTextDanglingPointer(); @@ -694,6 +695,30 @@ void tst_QOpenGLWidget::offscreenThenOnscreen() QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255)); } +void tst_QOpenGLWidget::paintWhileHidden() +{ + QScopedPointer tlw(new QWidget); + tlw->resize(640, 480); + + ClearWidget *w = new ClearWidget(0, 640, 480); + w->setParent(tlw.data()); + w->setClearColor(0, 0, 1); + + tlw->show(); + QVERIFY(QTest::qWaitForWindowExposed(tlw.data())); + + // QTBUG-101620: Now make visible=false and call update and see if we get to + // paintEvent/paintGL eventually, to ensure the updating of the texture is + // not optimized permanently away even though there is no composition + // on-screen at the point when update() is called. + + w->setVisible(false); + w->m_paintCalled = 0; + w->update(); + w->setVisible(true); + QTRY_VERIFY(w->m_paintCalled > 0); +} + class StaticTextPainterWidget : public QOpenGLWidget { public: