KDAB / KDDockWidgets

KDAB's Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets
Other
762 stars 164 forks source link

Restore maximized window state while it's currently maximized doesn't work #499

Closed bbc131 closed 5 months ago

bbc131 commented 5 months ago

If you set the window to "maximized", save the layout and later, while the window again is in a "maximized" state, restore the saved layout, it'll be set to "normal". This issue is similar to #477, but a slightly different case.

I can reproduce this with the qtwidgets_dockwidgets example as well as with TestNativeQPA::tst_restoreMaximizedFromNormal, when removing the following two lines:

m->view()->showNormal();
QVERIFY(filter.waitForState(Qt::WindowNoState));

Note, that this test then covers only the case where, before restoring, the window is maximized on the same screen as it shall be restored. But this doesn't need to be the case.

I had a look at LayoutSaver::restoreLayout and at // 1. Restore main windows the else-path is taken and within deserializeWindowGeometry the saved.normalGeometry is applied. There is a comment Later it's maximized ..., which makes sense, but this maximization later on simply seems to be missing. If I add the following snippet at the end of deserializeWindowGeometry, the problem seems to be fixed, but this works only for Qt6!

    if (!isNormalWindowState(saved.windowState))
    {
        window->setWindowState(saved.windowState);
    }

I quite don't understand what should be handled within deserializeWindowGeometry and what within the if in restoreLayout. Adding another else if path in the latter fixes the problem for Qt6 and Qt5:

} else if (window->windowState() == WindowState::Maximized && mw.windowState == WindowState::Maximized) {
    // Never call deserializeWindowGeometry() on a maximized window.
    // If window is maximized and we're restoring it to "maximized", then 1st change state to "normal", 
    // then set geometry and finally set it to "maximized" again.
    window->setWindowState(WindowState::None);
    d->deserializeWindowGeometry(mw, window);
    window->setWindowState(mw.windowState);
iamsergio commented 5 months ago

Let's see if the CI says. At least on Windows, the new test and the 2 previous tests still pass.

iamsergio commented 5 months ago

yeah, still passing