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. When window goes fullscreen, show something different
QtWS25 Last Chance

When window goes fullscreen, show something different

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 5 Posters 3.8k 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.
  • L Offline
    L Offline
    l1psync
    wrote on 11 Aug 2019, 22:14 last edited by l1psync 8 Dec 2019, 18:58
    #1

    Hey there,

    I currently work on a macOS-only application (don't want to port my app at the moment) and I want to do some simple thing which doesn't quite work as I except.
    Anytime when a user maximizes my QMainWindow (it would go fullscreen then, over the green button in the macOS bar) I want to show another window (based on QWidget) instead of my QMainWindow going fullscreen. I tried it with changeEvent() just like this.

    // just some testin' around
    void MainWindow::changeEvent(QEvent *event) {
    	QWidget *testWidget = new QWidget();
    
    	if (event->type() == QEvent::WindowStateChange) {
    		if (isMaximized()) {
    			testWidget->showFullScreen();
    		}
    	}
    }
    

    Sadly, this doesn't do anything. Any thoughts how I can achieve this? I just want to catch if someone tries to maximize/fullscreen the app over the titlebar and when yes just show another window in fullscreen and let my QMainWindow stay as it is.

    Kind regards,
    Jan

    P 1 Reply Last reply 12 Aug 2019, 07:41
    0
    • L l1psync
      11 Aug 2019, 22:14

      Hey there,

      I currently work on a macOS-only application (don't want to port my app at the moment) and I want to do some simple thing which doesn't quite work as I except.
      Anytime when a user maximizes my QMainWindow (it would go fullscreen then, over the green button in the macOS bar) I want to show another window (based on QWidget) instead of my QMainWindow going fullscreen. I tried it with changeEvent() just like this.

      // just some testin' around
      void MainWindow::changeEvent(QEvent *event) {
      	QWidget *testWidget = new QWidget();
      
      	if (event->type() == QEvent::WindowStateChange) {
      		if (isMaximized()) {
      			testWidget->showFullScreen();
      		}
      	}
      }
      

      Sadly, this doesn't do anything. Any thoughts how I can achieve this? I just want to catch if someone tries to maximize/fullscreen the app over the titlebar and when yes just show another window in fullscreen and let my QMainWindow stay as it is.

      Kind regards,
      Jan

      P Offline
      P Offline
      Pl45m4
      wrote on 12 Aug 2019, 07:41 last edited by Pl45m4 8 Dec 2019, 07:42
      #2

      @l1psync

      ChangeEvent is not the right event for this.
      https://doc.qt.io/qt-5/qwidget.html#changeEvent

      Try ResizeEvent instead.
      https://doc.qt.io/qt-5/qwidget.html#resizeEvent

      @l1psync said in When window is maximized, show something different:

      I want to show another window (based on QWidget) instead of my QMainWindow going fullscreen.

      I dont know what will happen, if you show two fullscreen windows, because like this, you cannot prevent the first window from getting expanded to fullscreen. So the first window is shown in fullscreen mode and the testWidget afterwards (some msecs delay)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      3
      • L Offline
        L Offline
        l1psync
        wrote on 12 Aug 2019, 15:19 last edited by
        #3

        Thank you but this does not work either. Here nothing really happens.

        void MainWindow::resizeEvent(QResizeEvent *event) {
        	if (isMaximized()) {
        		fsWindow->show();
        	}
        }
        

        No matter how I change it (even with event->type() ==).

        Is there no real way to catch up the title bar interaction in general? Something like "isGoingFullScreen"?

        M 1 Reply Last reply 12 Aug 2019, 15:34
        0
        • L l1psync
          12 Aug 2019, 15:19

          Thank you but this does not work either. Here nothing really happens.

          void MainWindow::resizeEvent(QResizeEvent *event) {
          	if (isMaximized()) {
          		fsWindow->show();
          	}
          }
          

          No matter how I change it (even with event->type() ==).

          Is there no real way to catch up the title bar interaction in general? Something like "isGoingFullScreen"?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 12 Aug 2019, 15:34 last edited by
          #4

          @l1psync
          Hi
          isMaximized() is not the same as isFullScreen()
          so make sure you are checking the right thing.

          L 1 Reply Last reply 12 Aug 2019, 18:35
          2
          • M mrjj
            12 Aug 2019, 15:34

            @l1psync
            Hi
            isMaximized() is not the same as isFullScreen()
            so make sure you are checking the right thing.

            L Offline
            L Offline
            l1psync
            wrote on 12 Aug 2019, 18:35 last edited by l1psync 8 Dec 2019, 18:50
            #5

            @mrjj
            Thanks, I forgot that (maximize/fullscreen in macOS is very irritating).

            So resizeEventdidn't work so I tried again with changeEvent

            void MainWindow::changeEvent(QEvent *event) {
            	if (event->type() == QEvent::WindowStateChange) {
            	if (isFullScreen()) {
            		fsWindow->showFullScreen();
            	}
            	}
            }
            

            That works actually but not in the behavior I want! When I now go fullscreen you can see that my QMainWindow is fullscreen and then shows the other window in fullscreen, you get a short view into that and then it switches into a black view. When I switch back I can go back to my new fullscreen window, if I close it my QMainWindow is not there. I am really confused right now... I think the black "fullscreen" window is actually my QMainWindow but it does not get "painted"... Any thoughts on that?

            EDIT: Ok, interesting, when I go out of fullscreen in my new window, I can see my QMainWindow behind the UI.
            screenshot

            The black "fullscreen" view still exists...
            https://streamable.com/r65x2 (video)

            P 1 Reply Last reply 12 Aug 2019, 18:52
            0
            • L l1psync
              12 Aug 2019, 18:35

              @mrjj
              Thanks, I forgot that (maximize/fullscreen in macOS is very irritating).

              So resizeEventdidn't work so I tried again with changeEvent

              void MainWindow::changeEvent(QEvent *event) {
              	if (event->type() == QEvent::WindowStateChange) {
              	if (isFullScreen()) {
              		fsWindow->showFullScreen();
              	}
              	}
              }
              

              That works actually but not in the behavior I want! When I now go fullscreen you can see that my QMainWindow is fullscreen and then shows the other window in fullscreen, you get a short view into that and then it switches into a black view. When I switch back I can go back to my new fullscreen window, if I close it my QMainWindow is not there. I am really confused right now... I think the black "fullscreen" window is actually my QMainWindow but it does not get "painted"... Any thoughts on that?

              EDIT: Ok, interesting, when I go out of fullscreen in my new window, I can see my QMainWindow behind the UI.
              screenshot

              The black "fullscreen" view still exists...
              https://streamable.com/r65x2 (video)

              P Offline
              P Offline
              Pl45m4
              wrote on 12 Aug 2019, 18:52 last edited by Pl45m4 8 Dec 2019, 18:58
              #6

              @l1psync

              Maximize and FullScreen are different things on every OS, not only on macOS :)

              Didn't notice that you are talking about Fullscreen but wrote Maximize.

              As I said, you cannot prevent the MainWindow from getting to Fullscreen Mode this way, but it should be possible in general.
              There are some similar threads in this forum, but for MS Windows only.

              Edit:
              Ref your edited post:
              I guess the OS loses the MainWindow after both windows are in fullscreen mode, because there can only be one fullscreen window at a time.
              So it's not getting updated / repainted anymore.
              If you find a way to interrupt the MainWindow from being expanded to fullscreen, then you should be fine :)
              (You'll need to access the macOS window manager)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              L 1 Reply Last reply 12 Aug 2019, 18:57
              1
              • P Pl45m4
                12 Aug 2019, 18:52

                @l1psync

                Maximize and FullScreen are different things on every OS, not only on macOS :)

                Didn't notice that you are talking about Fullscreen but wrote Maximize.

                As I said, you cannot prevent the MainWindow from getting to Fullscreen Mode this way, but it should be possible in general.
                There are some similar threads in this forum, but for MS Windows only.

                Edit:
                Ref your edited post:
                I guess the OS loses the MainWindow after both windows are in fullscreen mode, because there can only be one fullscreen window at a time.
                So it's not getting updated / repainted anymore.
                If you find a way to interrupt the MainWindow from being expanded to fullscreen, then you should be fine :)
                (You'll need to access the macOS window manager)

                L Offline
                L Offline
                l1psync
                wrote on 12 Aug 2019, 18:57 last edited by l1psync 8 Dec 2019, 19:01
                #7

                @pl45m4 Even though the QMainWindow is going to fullscreen, its ok for me for first (probably later try minimizing the app). But this strange behavior that some random black fullscreen view opens up is confusing me...

                P 1 Reply Last reply 12 Aug 2019, 19:03
                0
                • L l1psync
                  12 Aug 2019, 18:57

                  @pl45m4 Even though the QMainWindow is going to fullscreen, its ok for me for first (probably later try minimizing the app). But this strange behavior that some random black fullscreen view opens up is confusing me...

                  P Offline
                  P Offline
                  Pl45m4
                  wrote on 12 Aug 2019, 19:03 last edited by
                  #8

                  @l1psync

                  Do you see the window title of that black window? Or anything which identifies the black window, so you can see where it actually comes from?


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  L 1 Reply Last reply 12 Aug 2019, 19:11
                  1
                  • P Pl45m4
                    12 Aug 2019, 19:03

                    @l1psync

                    Do you see the window title of that black window? Or anything which identifies the black window, so you can see where it actually comes from?

                    L Offline
                    L Offline
                    l1psync
                    wrote on 12 Aug 2019, 19:11 last edited by
                    #9

                    @pl45m4
                    No I cannot see the title bar nor the menu bar.

                    There can be a lot of fullscreen windows because each window then is getting its „own desktop“.

                    My thoughts were that the black view and the QMainWindow are in real one piece and result in a fullscreen QMainWindow. I tried repaint on it but this does not work.

                    P 1 Reply Last reply 12 Aug 2019, 21:05
                    0
                    • L l1psync
                      12 Aug 2019, 19:11

                      @pl45m4
                      No I cannot see the title bar nor the menu bar.

                      There can be a lot of fullscreen windows because each window then is getting its „own desktop“.

                      My thoughts were that the black view and the QMainWindow are in real one piece and result in a fullscreen QMainWindow. I tried repaint on it but this does not work.

                      P Offline
                      P Offline
                      Pl45m4
                      wrote on 12 Aug 2019, 21:05 last edited by Pl45m4 8 Dec 2019, 21:07
                      #10

                      @l1psync

                      Ok, the "own-desktop"-thing is Mac related (I'm not a mac-expert)

                      What happens if you set only the MainWindow to fullscreen without the new widget? Do you get a black screen on one virtual desktop too?


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      L 1 Reply Last reply 12 Aug 2019, 21:19
                      0
                      • P Pl45m4
                        12 Aug 2019, 21:05

                        @l1psync

                        Ok, the "own-desktop"-thing is Mac related (I'm not a mac-expert)

                        What happens if you set only the MainWindow to fullscreen without the new widget? Do you get a black screen on one virtual desktop too?

                        L Offline
                        L Offline
                        l1psync
                        wrote on 12 Aug 2019, 21:19 last edited by
                        #11

                        @pl45m4
                        I just get my Mainwindow in fullscreen. No black view.

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          l1psync
                          wrote on 12 Aug 2019, 21:31 last edited by l1psync 8 Dec 2019, 21:32
                          #12

                          I am now 100% sure the black view has something to do with my application. When I move into the "desktop overview" I can see that the black view has the name of my application. So its probably that the QMainWindow does not gets painted.

                          I think I know what the problem is and that is on the side of macOS. When I call just showmy new QWidget is just showing up without any mistakes (but not in fullscreen). The problem here is probably that I try to launch another window in fullscreen while I am in fullscreen. So the solution to that would be catching up before we go fullscreen. But as I think there's no Qt solution to that, or am I wrong?

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            l1psync
                            wrote on 12 Aug 2019, 21:47 last edited by l1psync 8 Dec 2019, 21:48
                            #13

                            BOOM, I got this!

                            void MainWindow::changeEvent(QEvent *event) {
                            	if (event->type() == QEvent::WindowStateChange) {
                            		Qt::WindowStates state = this->windowState(); // debug reasons
                            		if (this->windowState() == Qt::WindowFullScreen) {
                            			appIsFs = true;
                            			showEditViewFs();
                            		}
                            	}
                            }
                            
                            void MainWindow::showEditViewFs() {
                            	if (appIsFs == true) {
                                    fsWindow->show();
                                    fsWindow->setWindowState(windowState() & Qt::WindowFullScreen);
                                    this->setWindowState(windowState() & ~(Qt::WindowFullScreen));
                            	}
                            }
                            

                            @Pl45m4 Now I am hanging here at the point that it just ignores the this->setWindowState(windowState() & ~(Qt::WindowFullScreen));.

                            J.HilkJ 1 Reply Last reply 13 Aug 2019, 05:27
                            0
                            • L l1psync
                              12 Aug 2019, 21:47

                              BOOM, I got this!

                              void MainWindow::changeEvent(QEvent *event) {
                              	if (event->type() == QEvent::WindowStateChange) {
                              		Qt::WindowStates state = this->windowState(); // debug reasons
                              		if (this->windowState() == Qt::WindowFullScreen) {
                              			appIsFs = true;
                              			showEditViewFs();
                              		}
                              	}
                              }
                              
                              void MainWindow::showEditViewFs() {
                              	if (appIsFs == true) {
                                      fsWindow->show();
                                      fsWindow->setWindowState(windowState() & Qt::WindowFullScreen);
                                      this->setWindowState(windowState() & ~(Qt::WindowFullScreen));
                              	}
                              }
                              

                              @Pl45m4 Now I am hanging here at the point that it just ignores the this->setWindowState(windowState() & ~(Qt::WindowFullScreen));.

                              J.HilkJ Offline
                              J.HilkJ Offline
                              J.Hilk
                              Moderators
                              wrote on 13 Aug 2019, 05:27 last edited by
                              #14

                              @l1psync
                              question, why do you make your 2nd Window as Independent window?

                              Let the QMainWindow go fullscreen, detect that, and simply exchange the content of or QMainWindow.

                              You can do that for example via setContentWidget, make sure to keep a valid pointer of your original contentWidget to realign it, once the fullscreen exits


                              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                              Q: What's that?
                              A: It's blue light.
                              Q: What does it do?
                              A: It turns blue.

                              L 1 Reply Last reply 13 Aug 2019, 12:10
                              3
                              • J.HilkJ J.Hilk
                                13 Aug 2019, 05:27

                                @l1psync
                                question, why do you make your 2nd Window as Independent window?

                                Let the QMainWindow go fullscreen, detect that, and simply exchange the content of or QMainWindow.

                                You can do that for example via setContentWidget, make sure to keep a valid pointer of your original contentWidget to realign it, once the fullscreen exits

                                L Offline
                                L Offline
                                l1psync
                                wrote on 13 Aug 2019, 12:10 last edited by
                                #15

                                @j-hilk Good point, you mean setCentralWidget(). I'll try it out...

                                J.HilkJ 1 Reply Last reply 13 Aug 2019, 12:12
                                1
                                • L l1psync
                                  13 Aug 2019, 12:10

                                  @j-hilk Good point, you mean setCentralWidget(). I'll try it out...

                                  J.HilkJ Offline
                                  J.HilkJ Offline
                                  J.Hilk
                                  Moderators
                                  wrote on 13 Aug 2019, 12:12 last edited by
                                  #16

                                  @l1psync said in When window goes fullscreen, show something different:

                                  @j-hilk Good point, you mean setCentralWidget()

                                  Yes, of course. Too much QML lately ;)
                                  https://doc.qt.io/qt-5/qmainwindow.html#setCentralWidget


                                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                  Q: What's that?
                                  A: It's blue light.
                                  Q: What does it do?
                                  A: It turns blue.

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 13 Aug 2019, 19:35 last edited by
                                    #17

                                    Hi,

                                    QStackedWidget comes to mind for that.

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    1
                                    • L Offline
                                      L Offline
                                      l1psync
                                      wrote on 14 Aug 2019, 14:06 last edited by
                                      #18

                                      Just like @SGaist with QStackedWidget this works perfectly. Thanks to everyone!

                                      1 Reply Last reply
                                      0

                                      3/18

                                      12 Aug 2019, 15:19

                                      15 unread
                                      • Login

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