Fix subwindow size on load (#8204)

---------

Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
This commit is contained in:
Yohanan
2026-06-30 13:17:28 -03:00
committed by GitHub
parent 45970566f8
commit cd9a0de459

View File

@@ -688,9 +688,6 @@ void MainWindow::saveWidgetState(QWidget* w, QDomElement& de)
de.setAttribute("height", normalGeometry.height());
}
void MainWindow::restoreWidgetState(QWidget* w, const QDomElement& de)
{
// TODO: Only use one of these
@@ -699,34 +696,28 @@ void MainWindow::restoreWidgetState(QWidget* w, const QDomElement& de)
{
// Fall back on parent
win = qobject_cast<SubWindow*>(w->parentWidget());
if (!win)
{
// Still could not find the window - soft fail
return;
}
// Still could not find the window - soft fail
if (!win) { return; }
}
const auto normalGeometry = QRect {
const auto normalGeometry = QRect{
de.attribute("x").toInt(),
de.attribute("y").toInt(),
de.attribute("width").toInt(),
de.attribute("height").toInt()
de.attribute("height").toInt(),
};
if (normalGeometry.isValid())
{
// first restore the window, as attempting to resize a maximized window causes graphics glitching
win->setWindowState(win->windowState() & ~(Qt::WindowMaximized | Qt::WindowMinimized));
// First restore the window, as attempting to resize a maximized window can cause graphical glitches.
win->setWindowState(win->windowState() & ~(Qt::WindowMaximized | Qt::WindowMinimized));
win->setGeometry(normalGeometry);
// Then resize it. `QWidget::setGeometry` adjusts the size if it is invalid / under the minimum size.
win->setGeometry(normalGeometry);
// set the window to its correct minimized/maximized/restored state
Qt::WindowStates winState = win->windowState();
winState = de.attribute("maximized").toInt()
? (winState | Qt::WindowMaximized)
: (winState & ~Qt::WindowMaximized);
win->setWindowState(winState);
}
// Set the window to its correct "maximized?" state.
auto winState = win->windowState();
winState.setFlag(Qt::WindowMaximized, de.attribute("maximized").toInt());
win->setWindowState(winState);
if (const auto visible = de.attribute("visible"); !visible.isEmpty())
{
@@ -734,9 +725,6 @@ void MainWindow::restoreWidgetState(QWidget* w, const QDomElement& de)
}
}
void MainWindow::emptySlot()
{
}