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. Problem with maximised window
Forum Updated to NodeBB v4.3 + New Features

Problem with maximised window

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.5k Views 1 Watching
  • 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.
  • PerdrixP Perdrix

    @ChrisW67 Hmm... I'm not sure that is the case regarding windowState, especially given that the window state byte array is much larger than the geometry byte array. I need to restore the window state to restore the size of the docked dock widgets.

    This problem is happening on Qt 6.5.1, Windows 11

    @Axel-Spoerl Any thoughts?

    PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #4

    Interesting: I reversed the order of the restoration so window state was restored first, but that made no difference.

    Debugging through the geometry restoration, the call to showMaximized did show the window maximised but when I then let the application run the title bar was off screen again, and the maximised indicator in the window decorations showed it was not maximised.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SamiV123
      wrote on last edited by SamiV123
      #5

      @Perdrix

      I recall having seem similar problems and I think the issues I had were these two:

      • trying to save the window geometry after it has been closed / or made invisible.
      • trying to save a QByteArray as such with QVariant/QJson/QSetting silently failing.

      For the second problem I now always base64 encode the byte arrays.

      In general I find it's much better to make your applications shutdown sequence always explicit and in such a shutdown function you do stuff as saving your state while all your resources (such as windows) are still allocated.

      Leave the destructor for simple cases only that have no impact on the program logic.

      PerdrixP 1 Reply Last reply
      0
      • S SamiV123

        @Perdrix

        I recall having seem similar problems and I think the issues I had were these two:

        • trying to save the window geometry after it has been closed / or made invisible.
        • trying to save a QByteArray as such with QVariant/QJson/QSetting silently failing.

        For the second problem I now always base64 encode the byte arrays.

        In general I find it's much better to make your applications shutdown sequence always explicit and in such a shutdown function you do stuff as saving your state while all your resources (such as windows) are still allocated.

        Leave the destructor for simple cases only that have no impact on the program logic.

        PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #6

        @SamiV123 I'm saving the geometry etc. in closeEvent() not the dtor. So all windows should still be present and correct.

        PerdrixP 1 Reply Last reply
        0
        • PerdrixP Perdrix

          @SamiV123 I'm saving the geometry etc. in closeEvent() not the dtor. So all windows should still be present and correct.

          PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by Perdrix
          #7

          Changing the code to read:

          	if (settings.contains("geometry") && settings.contains("maximised"))
          	{
          		const QByteArray geometry{ settings.value("geometry").toByteArray() };
          		const bool maximised{ settings.value("maximised").toBool() };
          
          		if (maximised)
          		{
          			setGeometry(screen()->availableGeometry());
          			showMaximized();
          		}
          		else
          		{
          			restoreGeometry(geometry);
          		}
          	}
          

          That's to say calling showMaximized() AFTER setGeometry(screen()-> etc..) seems to have resolved the problem.

          Can someone please clarify the officially correct way to do this and the exact order in which it should be done (window state, geometry, showMaximized()).

          S 1 Reply Last reply
          0
          • PerdrixP Perdrix

            Changing the code to read:

            	if (settings.contains("geometry") && settings.contains("maximised"))
            	{
            		const QByteArray geometry{ settings.value("geometry").toByteArray() };
            		const bool maximised{ settings.value("maximised").toBool() };
            
            		if (maximised)
            		{
            			setGeometry(screen()->availableGeometry());
            			showMaximized();
            		}
            		else
            		{
            			restoreGeometry(geometry);
            		}
            	}
            

            That's to say calling showMaximized() AFTER setGeometry(screen()-> etc..) seems to have resolved the problem.

            Can someone please clarify the officially correct way to do this and the exact order in which it should be done (window state, geometry, showMaximized()).

            S Offline
            S Offline
            SamiV123
            wrote on last edited by SamiV123
            #8

            @Perdrix said in Problem with maximised window:

            Changing the code to read:

            	if (settings.contains("geometry") && settings.contains("maximised"))
            	{
            		const QByteArray geometry{ settings.value("geometry").toByteArray() };
            		const bool maximised{ settings.value("maximised").toBool() };
            
            		if (maximised)
            		{
            			setGeometry(screen()->availableGeometry());
            			showMaximized();
            		}
            		else
            		{
            			restoreGeometry(geometry);
            		}
            	}
            

            That's to say calling showMaximized() AFTER setGeometry(screen()-> etc..) seems to have resolved the problem.

            Can someone please clarify the officially correct way to do this and the exact order in which it should be done.

            I think it's a red herring,

            your "maximized" flag is saves as a bool in the settings so you get that value back properly while your geometry byte buffer is mangled.

            Your maximized should be part of the geometry state already.

            Try base64 encoding your geometry buffer like I suggested before.

            PerdrixP 2 Replies Last reply
            0
            • S SamiV123

              @Perdrix said in Problem with maximised window:

              Changing the code to read:

              	if (settings.contains("geometry") && settings.contains("maximised"))
              	{
              		const QByteArray geometry{ settings.value("geometry").toByteArray() };
              		const bool maximised{ settings.value("maximised").toBool() };
              
              		if (maximised)
              		{
              			setGeometry(screen()->availableGeometry());
              			showMaximized();
              		}
              		else
              		{
              			restoreGeometry(geometry);
              		}
              	}
              

              That's to say calling showMaximized() AFTER setGeometry(screen()-> etc..) seems to have resolved the problem.

              Can someone please clarify the officially correct way to do this and the exact order in which it should be done.

              I think it's a red herring,

              your "maximized" flag is saves as a bool in the settings so you get that value back properly while your geometry byte buffer is mangled.

              Your maximized should be part of the geometry state already.

              Try base64 encoding your geometry buffer like I suggested before.

              PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by
              #9

              @SamiV123 I don't believe that's the case - please see:

              https://bugreports.qt.io/browse/QTBUG-46620

              and

              https://stackoverflow.com/questions/44005852/qdockwidgetrestoregeometry-not-working-correctly-when-qmainwindow-is-maximized

              David

              1 Reply Last reply
              0
              • S SamiV123

                @Perdrix said in Problem with maximised window:

                Changing the code to read:

                	if (settings.contains("geometry") && settings.contains("maximised"))
                	{
                		const QByteArray geometry{ settings.value("geometry").toByteArray() };
                		const bool maximised{ settings.value("maximised").toBool() };
                
                		if (maximised)
                		{
                			setGeometry(screen()->availableGeometry());
                			showMaximized();
                		}
                		else
                		{
                			restoreGeometry(geometry);
                		}
                	}
                

                That's to say calling showMaximized() AFTER setGeometry(screen()-> etc..) seems to have resolved the problem.

                Can someone please clarify the officially correct way to do this and the exact order in which it should be done.

                I think it's a red herring,

                your "maximized" flag is saves as a bool in the settings so you get that value back properly while your geometry byte buffer is mangled.

                Your maximized should be part of the geometry state already.

                Try base64 encoding your geometry buffer like I suggested before.

                PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by Perdrix
                #10

                Arghh! If I now close the application while it is maximised and restart it, when I restore the window from maximised it doesn't go back the the size it was before it was maximised, but to the default initial size that would apply if there were no saved geometry or state.

                If I maximise/restore without closing everything works as I expect.

                David

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SamiV123
                  wrote on last edited by SamiV123
                  #11

                  I just checked what I've done in my own app, I also have a "MainWindow" with a QDockWidget and all I seem to be doing is to call QMainWindow::saveState and then restoreState and this works for me for restoring the dock state.

                  Then I use x(), y(), width() and height() to save the window geometry explicitly.

                  This has worked for me on Linux with X11 including fully maximized window.

                  FWIW I'm also doing the base64 encode step since I also spent time struggling with this same problem.

                  PerdrixP 1 Reply Last reply
                  0
                  • S SamiV123

                    I just checked what I've done in my own app, I also have a "MainWindow" with a QDockWidget and all I seem to be doing is to call QMainWindow::saveState and then restoreState and this works for me for restoring the dock state.

                    Then I use x(), y(), width() and height() to save the window geometry explicitly.

                    This has worked for me on Linux with X11 including fully maximized window.

                    FWIW I'm also doing the base64 encode step since I also spent time struggling with this same problem.

                    PerdrixP Offline
                    PerdrixP Offline
                    Perdrix
                    wrote on last edited by
                    #12

                    @Volker-Hilsheimer Any thoughts?

                    PerdrixP 1 Reply Last reply
                    0
                    • PerdrixP Perdrix

                      @Volker-Hilsheimer Any thoughts?

                      PerdrixP Offline
                      PerdrixP Offline
                      Perdrix
                      wrote on last edited by
                      #13

                      Reported under https://bugreports.qt.io/browse/QTBUG-118598

                      1 Reply Last reply
                      0

                      • Login

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