diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 6131491aaa1..c0896e87d99 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -10908,10 +10908,12 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) << "to support" << surfaceType; const auto windowStateBeforeDestroy = newParentWithWindow->windowState(); const auto visibilityBeforeDestroy = newParentWithWindow->isVisible(); + const auto positionBeforeDestroy = newParentWithWindow->pos(); newParentWithWindow->destroy(); newParentWithWindow->create(); Q_ASSERT(newParentWithWindow->windowHandle()); newParentWithWindow->windowHandle()->setWindowStates(windowStateBeforeDestroy); + newParentWithWindow->move(positionBeforeDestroy); QWidgetPrivate::get(newParentWithWindow)->setVisible(visibilityBeforeDestroy); } else if (auto *backingStore = newParentWithWindow->backingStore()) { // If we don't recreate we still need to make sure the native parent diff --git a/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp b/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp index 64ebeb08b0d..261ea56b345 100644 --- a/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp +++ b/tests/auto/widgets/kernel/qwidgetrepaintmanager/tst_qwidgetrepaintmanager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -261,6 +262,7 @@ private slots: void scroll(); void paintOnScreenUpdates(); void evaluateRhi(); + void rhiRecreateMaintainsWindowProperties(); #if defined(QT_BUILD_INTERNAL) void scrollWithOverlap(); @@ -798,6 +800,29 @@ void tst_QWidgetRepaintManager::evaluateRhi() #endif // QT_CONFIG(opengl) } +void tst_QWidgetRepaintManager::rhiRecreateMaintainsWindowProperties() +{ + const auto *integration = QGuiApplicationPrivate::platformIntegration(); + if (!integration->hasCapability(QPlatformIntegration::RhiBasedRendering)) + QSKIP("Platform does not support RHI based rendering"); + +#if !QT_CONFIG(opengl) + QSKIP("Platform does not support OpenGL RHI based rendering"); +#endif + + // Reparenting Rhi widget into a window causes the window to be + // recreated, but after recreation the window properties such as + // window position must remain the same + QMainWindow topLevel; + topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QPoint windowPos = topLevel.pos(); + RhiWidget nativeRhiWidget(QPlatformBackingStoreRhiConfig::OpenGL, &topLevel); + QVERIFY(QWidgetPrivate::get(&topLevel)->usesRhiFlush); + QVERIFY(QWidgetPrivate::get(&topLevel)->rhi()); + QCOMPARE(topLevel.pos(), windowPos); +} + #if defined(QT_BUILD_INTERNAL) /*!