Implementing fullscreen mode - frameless window that hides the taskbar
-
wrote on 21 Jul 2015, 05:59 last edited by NetZwerg
Try adding
QMainWindow::setWindowFlags(Qt::FramelessWindowHint);
-
wrote on 25 Jul 2015, 12:04 last edited by Violet Giraffe
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
showFullScreen
call 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
/restoreGeometry
methods. -
wrote on 25 Jul 2015, 12:15 last edited by
Hi, using the following function works for me:
void QWindow::setWindowState(Qt::WindowState state)
with stateQt::WindowFullScreen
. -
wrote on 25 Jul 2015, 12:17 last edited by Violet Giraffe
That has the same effect as
showFullscreen
. Perhaps, the implementation is the same. I findshowFullscreen
much 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
raise
andactivateWindow
are 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 findshowFullscreen
much 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
raise
andactivateWindow
are 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.wrote on 25 Jul 2015, 12:22 last edited by A Former User@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() const
and 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() const
and restore it when you need to. This also automatically restores the previous geometry.wrote on 25 Jul 2015, 12:32 last edited by Violet Giraffe@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. -
wrote on 25 Jul 2015, 15:19 last edited by Violet Giraffe
showNormal
alone 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?
-
wrote on 26 Jul 2015, 14:09 last edited by
Re-checked and confirmed:
showNormal
works properly in conjunction withshowFullScreen
.
11/11