Fix losing QOpenGLWidget paints when a child widget is invisible

Pick-to: 6.3 6.2
Change-Id: I136b486d30e31acadd6b1b837dc7e834ee3e23fb
Fixes: QTBUG-101620
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
bb10
Laszlo Agocs 2022-03-10 15:14:43 +01:00
parent dd0c886783
commit 1ea73bc29b
2 changed files with 32 additions and 0 deletions

View File

@ -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;

View File

@ -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<QWidget> 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: