Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Implementing fullscreen mode - frameless window that hides the taskbar

Implementing fullscreen mode - frameless window that hides the taskbar

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 10.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on 21 Jul 2015, 05:19 last edited by
    #1

    I'm trying to make a true fullscreen window (not just maximized one). Experimenting on Windows for now. According to this article a window should be able to hide the taskbar, i. e. have a higher z-order. But this code

    setGeometry(qApp->desktop()->geometry());

    only produces this result: http://i.imgur.com/XXPkqdz.jpg
    and this message in the output:

    QWindowsWindow::setGeometryDp: Unable to set geometry 1920x1080+0+0 on QWidgetWindow/'CMainWindowWindow'. Resulting geometry: 1916x1054+0+0 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 568x323, maximum size: 16777215x16777215).

    How can achieve what I want? The screenshot looks great, except that the taskbar is drawn over my window, and I need it to be the other way around.

    1 Reply Last reply
    1
    • N Offline
      N Offline
      NetZwerg
      wrote on 21 Jul 2015, 05:59 last edited by NetZwerg
      #2

      Try adding

      QMainWindow::setWindowFlags(Qt::FramelessWindowHint);
      
      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on 25 Jul 2015, 12:04 last edited by Violet Giraffe
        #3

        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 the saveGeometry / restoreGeometry methods.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 25 Jul 2015, 12:15 last edited by
          #4

          Hi, using the following function works for me:
          void QWindow::setWindowState(Qt::WindowState state) with state Qt::WindowFullScreen.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on 25 Jul 2015, 12:17 last edited by Violet Giraffe
            #5

            That has the same effect as showFullscreen. Perhaps, the implementation is the same. I find showFullscreen much more neat.

            For restoring, I call QRect savedGeometry = geometry() before showFullscreen, and then when I need to get back to a regular window:

            showNormal();
            setGeometry(_nonFullscreenWindowGeometry);
            raise();
            activateWindow();
            

            Not sure if raise and activateWindow 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.

            ? 1 Reply Last reply 25 Jul 2015, 12:22
            0
            • V Violet Giraffe
              25 Jul 2015, 12:17

              That has the same effect as showFullscreen. Perhaps, the implementation is the same. I find showFullscreen much more neat.

              For restoring, I call QRect savedGeometry = geometry() before showFullscreen, and then when I need to get back to a regular window:

              showNormal();
              setGeometry(_nonFullscreenWindowGeometry);
              raise();
              activateWindow();
              

              Not sure if raise and activateWindow 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.

              ? Offline
              ? Offline
              A Former User
              wrote on 25 Jul 2015, 12:22 last edited by A Former User
              #6

              @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.

              V 1 Reply Last reply 25 Jul 2015, 12:32
              1
              • ? A Former User
                25 Jul 2015, 12:22

                @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.

                V Offline
                V Offline
                Violet Giraffe
                wrote on 25 Jul 2015, 12:32 last edited by Violet Giraffe
                #7

                @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.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on 25 Jul 2015, 13:52 last edited by
                  #8

                  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() and showFullScreen(). They might be more convenient than tracking the state flags, depending on your need.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Violet Giraffe
                    wrote on 25 Jul 2015, 15:19 last edited by Violet Giraffe
                    #9

                    showNormal alone doesn't restore the original geometry, it just exits the full screen mode.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on 25 Jul 2015, 20:51 last edited by
                      #10

                      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?

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        Violet Giraffe
                        wrote on 26 Jul 2015, 14:09 last edited by
                        #11

                        Re-checked and confirmed: showNormal works properly in conjunction with showFullScreen.

                        1 Reply Last reply
                        0

                        2/11

                        21 Jul 2015, 05:59

                        9 unread
                        • Login

                        • Login or register to search.
                        2 out of 11
                        • First post
                          2/11
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved