Implementing fullscreen mode - frameless window that hides the taskbar
-
Finally got time to return to this task.
If I do as you suggested, the window just disappears both from screen and from the taskbar (no button, which is typical for frameless windows).UPDATE: Turns out, a mere
showFullScreencall does the trick. What got me confused previously when I tried was that there's a ~1 second delay between the window maximizing and the taskbar disappearing.
Now the only problem I have is how to restore the original size and position of the window. Guess I'm gonna have to use thesaveGeometry/restoreGeometrymethods. -
Hi, using the following function works for me:
void QWindow::setWindowState(Qt::WindowState state)with stateQt::WindowFullScreen. -
That has the same effect as
showFullscreen. Perhaps, the implementation is the same. I findshowFullscreenmuch more neat.For restoring, I call
QRect savedGeometry = geometry()beforeshowFullscreen, and then when I need to get back to a regular window:showNormal(); setGeometry(_nonFullscreenWindowGeometry); raise(); activateWindow();Not sure if
raiseandactivateWindoware necessary, it's just a code snippet I see in many different Qt projects that's called when window state changes. Could be a fix for some very old Qt bug that's been fixed long ago, for all I know. -
That has the same effect as
showFullscreen. Perhaps, the implementation is the same. I findshowFullscreenmuch more neat.For restoring, I call
QRect savedGeometry = geometry()beforeshowFullscreen, and then when I need to get back to a regular window:showNormal(); setGeometry(_nonFullscreenWindowGeometry); raise(); activateWindow();Not sure if
raiseandactivateWindoware necessary, it's just a code snippet I see in many different Qt projects that's called when window state changes. Could be a fix for some very old Qt bug that's been fixed long ago, for all I know.@Violet-Giraffe Yes, it has the same effect. You said you want to restore the window's previous geometry: You can just read the current state with
Qt::WindowState QWindow::windowState() constand restore it when you need to. This also automatically restores the previous geometry. -
@Violet-Giraffe Yes, it has the same effect. You said you want to restore the window's previous geometry: You can just read the current state with
Qt::WindowState QWindow::windowState() constand restore it when you need to. This also automatically restores the previous geometry.@Wieland said:
This also automatically restores the previous geometry.
That's neat!
setWindowState(windowState() & ~Qt::WindowFullScreen)works like charm (at least on Windows 7), no need for any additional member variables.
Thanks. -
Also note there's a
showNormal()method that does the same as tinkering with windows states.
There are basically 4 methods for setting the state:showNormal(),showMaximized(),showMinimized()andshowFullScreen(). They might be more convenient than tracking the state flags, depending on your need. -
showNormalalone doesn't restore the original geometry, it just exits the full screen mode. -
That's... weird. The implementation is basically the same, i.e.
void QWidget::showNormal() { ensurePolished(); setWindowState(windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)); setVisible(true); }I wonder if that's some bug then?
-
Re-checked and confirmed:
showNormalworks properly in conjunction withshowFullScreen.