Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: "normal" window size lost when switching to maximized state and then to fullscreen

I have an Qt application that can be displayed either "normal" (a normal window that's neither maximized nor minimized), maximized or fullscreen. I achieve that by calling the functions QWidget::showNormal(), QWidget::showMaximized() and QWidget::showFullscreen().

Let me first of all explain what does work:

  1. Going from normal to maximized and back works. Qt remembers the window size and position of the normal window and then restores that when exiting the maximized state.
  2. Going from normal to fullscreen and back works. Also here the size and position of the normal window is maintained.

What doesn't work?

When going from normal to maximized, then to fullscreen, back to maximized and then back to normal that does not work as expected. The window will not be resized to the size that it had originally, before maximizing. Instead the window will be as large as the screen (basically as large as the OS allows the window to be).

If I now go to fullscreen again then in the right upper corner and on the bottom edge there are weird artifacts that seem to look like parts of an old Vista window frame with visual effects disabled.

Here is an image that should illustrate the process I just explained:

enter image description here

I tried to save the last size of the window using QWidget::saveGeometry() or just saving the size obtained by QWidget::size() when a window state change event occured, but there were always cases when it behaved strangely. Apart from that, that last step when going full screen again looks like a bug to me.

What do you think?

UPDATE:

If I resize the window manually (to an arbitrary size) before the last step (which is going to fullscreen again), the fullscreen works without problems.

like image 280
bweber Avatar asked Oct 18 '25 10:10

bweber


1 Answers

Try doing showNormal() before showFullScreen() when the window is maximised and going to fullscreen.

when going to fullscreen

if (wasMaximized = isMaximized())
{
    setVisible(false);  // prevents window animation on showNormal() call 
    showNormal();
    setVisible(true);
}
showFullScreen();

when returning from fullscreen

if (isFullScreen())
{
    if (wasMaximized)
        showMaximized();
    else
        showNormal();
}
like image 167
Jim R. Avatar answered Oct 21 '25 04:10

Jim R.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!