Resize after changing window state in quick succession ⇒ problem

I tried the following lines:

    setWindowState(Qt::WindowNoState); // F1
    resize(imageSize); // F2
    showNormal(); // F1
    resize(imageSize); // F2
    setWindowState(Qt::WindowNoState); // F1
    setGeometry(QRect({}, imageSize)); // F2
    showNormal(); // F1
    setGeometry(QRect({}, imageSize)); // F2
    setUpdatesEnabled(false);
    setWindowState(Qt::WindowNoState); // F1
    setUpdatesEnabled(true);
    resize(imageSize); // F2

And the same combinations of F1 and F2 as in 1 to 4.

Result:
Whenever the Window state was Maximised or Fullscreen before running the part of code, the effect of F2 was undone (the resize occurred and then in < 500ms the window went back to the state before the resize(...)).

So I tried:

    QTimer::singleShot(delay_time, [this, imageSize]() { resize(imageSize); });
  1. With delay_time = 0 the window acted the same as cases 1 to 5.
  2. With delay_time = 10 I got a visual glitch which continued until I resized the window again (via mouse interaction or via in program code).
    • I will try and attach a suitable screen recording for it.
  3. With delay_time = 100, the window acted as expected. But 100ms is a long enough value to be user noticeable.

The full code is at Aditya Tolikar / qView_nolfs · GitLab
The changes in question are in the file src/mainwindow.cpp
The latest commit has the workaround as shown in Case 8. You can play around with it to see what it does on other systems.


I am interested in understanding what might be the cause of the problem. Whether it has to do with kwin or Qt or my code itself.

I tried something similar with SDL 3.

	SDL_SetWindowFullscreen(win, false); // F1
	SDL_SetWindowSize(win, 1200, 700); // F2

And it didn’t give any of the glitches observed in the Qt window.
I also expected requiring to use SDL_SyncWindow() in between the 2 but it worked fine without it.
So somehow, the problem doesn’t happen with SDL.

I thought it might have had something to do with refresh, so in qView (the code as linked in the post), after invoking the bug-causing code (with delay_time = 10 which causes the decorations to start glitching), I tried changing the displayed image, which would cause an update. But that didn’t seem to stop the glitchy effects.


I saw an article (a copy of one) that told how setWindowState had a problem with X11 and using showNormal instead, would fix the problem. But that doesn’t seem to be making a difference here.

I am also worried that the same 100ms might not be good enough for some systems while others might only require 10ms.
Currently, the only way I see to properly fix this is by emitting a signal from resizeEvent and using that in this part of the code.