diff --git a/src/widgets/kernel/qwidgetrepaintmanager.cpp b/src/widgets/kernel/qwidgetrepaintmanager.cpp index c4e557fb2f..7445255ad4 100644 --- a/src/widgets/kernel/qwidgetrepaintmanager.cpp +++ b/src/widgets/kernel/qwidgetrepaintmanager.cpp @@ -922,9 +922,6 @@ void QWidgetRepaintManager::paintAndFlush() if (hasPlatformWindow(w) || (npw && npw != tlw)) { if (!hasPlatformWindow(w)) w = npw; - QWidgetPrivate *wPrivate = w->d_func(); - if (!wPrivate->needsFlush) - wPrivate->needsFlush = new QRegion; appendDirtyOnScreenWidget(w); } } @@ -1039,29 +1036,27 @@ void QWidgetRepaintManager::markDirtyOnScreen(const QRegion ®ion, QWidget *wi return; } - // Alien widgets with native parent != tlw. - QWidgetPrivate *nativeParentPrivate = nativeParent->d_func(); - if (!nativeParentPrivate->needsFlush) - nativeParentPrivate->needsFlush = new QRegion; + // Alien widgets with native parent != tlw const QPoint nativeParentOffset = widget->mapTo(nativeParent, QPoint()); - *nativeParentPrivate->needsFlush += region.translated(nativeParentOffset); - appendDirtyOnScreenWidget(nativeParent); + appendDirtyOnScreenWidget(nativeParent, region.translated(nativeParentOffset)); return; } - // Native child widgets. - QWidgetPrivate *widgetPrivate = widget->d_func(); - if (!widgetPrivate->needsFlush) - widgetPrivate->needsFlush = new QRegion; - *widgetPrivate->needsFlush += region; - appendDirtyOnScreenWidget(widget); + // Native child widgets + appendDirtyOnScreenWidget(widget, region); } -void QWidgetRepaintManager::appendDirtyOnScreenWidget(QWidget *widget) +void QWidgetRepaintManager::appendDirtyOnScreenWidget(QWidget *widget, const QRegion ®ion) { if (!widget) return; + auto *widgetPrivate = qt_widget_private(widget); + if (!widgetPrivate->needsFlush) + widgetPrivate->needsFlush = new QRegion; + + *widgetPrivate->needsFlush += region; + if (!dirtyOnScreenWidgets.contains(widget)) dirtyOnScreenWidgets.append(widget); } diff --git a/src/widgets/kernel/qwidgetrepaintmanager_p.h b/src/widgets/kernel/qwidgetrepaintmanager_p.h index 470d63f99e..7d58adec99 100644 --- a/src/widgets/kernel/qwidgetrepaintmanager_p.h +++ b/src/widgets/kernel/qwidgetrepaintmanager_p.h @@ -113,7 +113,7 @@ private: bool syncAllowed(); void paintAndFlush(); - void appendDirtyOnScreenWidget(QWidget *widget); + void appendDirtyOnScreenWidget(QWidget *widget, const QRegion ®ion = QRegion()); void flush(QWidget *widget = nullptr); void flush(QWidget *widget, const QRegion ®ion, QPlatformTextureList *widgetTextures);