Restore window state of recreated top level widget, not closest QWindow
When we recreate a top level QWidget due to the RHI config not matching, we need to re-apply the window state, as the state is lost on destroy(). But we should do this on the QWidget we are recreating, not on its closest QWindow. These are usually the same, so it didn't matter in practice for most cases (besides the more convoluted way of getting to the QWidget's window). But if the top level widget does not have a winId yet, the call to find the closest QWindow via QWidgetPrivate::windowHandle() will traverse from the top level widget to its transient parent widget, via nativeParentWidget, which is strange and likely a bug. As a result of that, we would store the window state of the transient parent widget, and then, once we had created() the new top level, we would apply the window state to the top level, which now had a winId. We can simplify all of this by just storing and applying the window state on the widget we are re-creating. There's no need to go via the closest QWindow for this. We do however need to set the window state on the widget's window, as going via QWidget will just bail out since the window state hasn't changed. Amends c88211d1e4ac12eb2ae4990703a4f73c7085d624 Fixes: QTBUG-119795 Pick-to: 6.6 6.5 Change-Id: I0ad6e7bbac5f29d095cc643e9a7094784e9a2122 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit aecedfed9ab763513af8fda5a2b208b263da3f65) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
7b774f6ce2
commit
fe434acac6
@ -10898,10 +10898,11 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
|
||||
recreate = true;
|
||||
}
|
||||
if (recreate) {
|
||||
auto oldState = d->windowHandle(QWidgetPrivate::WindowHandleMode::Closest)->windowState();
|
||||
const auto windowStateBeforeDestroy = newtlw->windowState();
|
||||
newtlw->destroy();
|
||||
newtlw->create();
|
||||
d->windowHandle(QWidgetPrivate::WindowHandleMode::Closest)->setWindowState(oldState);
|
||||
Q_ASSERT(newtlw->windowHandle());
|
||||
newtlw->windowHandle()->setWindowStates(windowStateBeforeDestroy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user