diff --git a/src/gui/painting/qbackingstorerhisupport.cpp b/src/gui/painting/qbackingstorerhisupport.cpp index e068f1880d9..3ce21dd35be 100644 --- a/src/gui/painting/qbackingstorerhisupport.cpp +++ b/src/gui/painting/qbackingstorerhisupport.cpp @@ -196,13 +196,14 @@ QRhiSwapChain *QBackingStoreRhiSupport::swapChainForWindow(QWindow *window) bool QBackingStoreRhiSupportWindowWatcher::eventFilter(QObject *obj, QEvent *event) { - if (event->type() == QEvent::PlatformSurface - && static_cast(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed) + if (event->type() == QEvent::WindowAboutToChangeInternal + || (event->type() == QEvent::PlatformSurface + && static_cast(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)) { QWindow *window = qobject_cast(obj); auto it = m_rhiSupport->m_swapchains.find(window); if (it != m_rhiSupport->m_swapchains.end()) { - qCDebug(lcQpaBackingStore) << "SurfaceAboutToBeDestroyed received for tracked window" << window << "cleaning up swapchain"; + qCDebug(lcQpaBackingStore) << event << "received for" << window << "- cleaning up swapchain"; auto data = *it; m_rhiSupport->m_swapchains.erase(it); data.reset(); // deletes 'this' diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 06c6e8fe2b6..9df563504ca 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -10684,9 +10684,15 @@ void qSendWindowChangeToTextureChildrenRecursively(QWidget *widget, QEvent::Type for (int i = 0; i < d->children.size(); ++i) { QWidget *w = qobject_cast(d->children.at(i)); - if (w && !w->isWindow() && QWidgetPrivate::get(w)->textureChildSeen) + if (w && !w->isWindow()) qSendWindowChangeToTextureChildrenRecursively(w, eventType); } + + // Notify QWidgetWindow after we've notified all child QWidgets + if (auto *window = d->windowHandle(QWidgetPrivate::WindowHandleMode::Direct)) { + QEvent e(eventType); + QCoreApplication::sendEvent(window, &e); + } } /*! @@ -10746,7 +10752,7 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) // texture-based widgets need a pre-notification when their associated top-level window changes // This is not under the wasCreated/newParent conditions above in order to also play nice with QDockWidget. - if (d->textureChildSeen && ((!parent && parentWidget()) || (parent && parent->window() != oldtlw))) + if ((oldtlw && oldtlw->d_func()->usesRhiFlush) && ((!parent && parentWidget()) || (parent && parent->window() != oldtlw))) qSendWindowChangeToTextureChildrenRecursively(this, QEvent::WindowAboutToChangeInternal); // If we get parented into another window, children will be folded @@ -10827,7 +10833,7 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) // texture-based widgets need another event when their top-level window // changes (more precisely, has already changed at this point) - if (d->textureChildSeen && oldtlw != window()) + if ((oldtlw && oldtlw->d_func()->usesRhiFlush) && oldtlw != window()) qSendWindowChangeToTextureChildrenRecursively(this, QEvent::WindowChangeInternal); if (!wasCreated) {