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. Window maximised state not retained over close
Forum Updated to NodeBB v4.3 + New Features

Window maximised state not retained over close

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 195 Views 2 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 Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    My application saves the geometry and state in my closeEvent handler:

    	QSettings settings;
    	settings.beginGroup("MainWindow");
    	auto geometry{ saveGeometry() };
    	settings.setValue("geometry", geometry);
    #ifndef NDEBUG	
    	ZTRACE_RUNTIME("Hex dump of geometry:");
    	ZTrace::dumpHex(geometry.constData(), geometry.length());
    #endif 
    
    	auto windowState{ saveState()};
    	settings.setValue("windowState", saveState());
    #ifndef NDEBUG	
    	ZTRACE_RUNTIME("Hex dump of windowState:");
    	ZTrace::dumpHex(windowState.constData(), windowState.length());
    #endif
    
    	settings.endGroup();
    

    When I reopen the application I do this in the main window startup code:

    	QSettings settings;
    	settings.beginGroup("MainWindow");
    
    	auto geometry{ settings.value("geometry", QByteArray()).toByteArray() };
    	auto windowState{ settings.value("windowState", QByteArray()).toByteArray() };
    
    #ifndef NDEBUG
    	if (geometry.length())
    	{
    		ZTRACE_RUNTIME("Hex dump of geometry:");
    		ZTrace::dumpHex(geometry.constData(), geometry.length());
    	}
    	if (windowState.length())
    	{
    		ZTRACE_RUNTIME("Hex dump of windowState:");
    		ZTrace::dumpHex(windowState.constData(), windowState.length());
    	}
    #endif
    
    	restoreGeometry(geometry);
    	restoreState(windowState);
    	settings.endGroup();
    

    This works most of the time, but if I maximise the application and then close it the window opens at the top left of the desktop with a relatively small size (1152 x 698) rather than maximised.

    What am I doing wrong please. I am sure it used to work on Qt 6.4.0 (this is 6.5.1)

    The hex dump of the window geometry and state at close time was:

    00000041 2023/10/04 04:18:39.307 050688 000023e8     >Hex dump of geometry:
    00000042 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822760:  01D9D0CB 00030000 00000000 FFFFFFF9  ................
    00000043 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822770:  00000398 0000022C 00000000 00000017  .......,........
    00000044 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822780:  00000398 0000022C 00000000 00000000  .......,........
    00000045 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822790:  0C000000 00000000 00170000 03980000  ................
    00000046 2023/10/04 04:18:39.308 050688 000023e8     >00000000038227A0:  022C                                 .,              
    00000047 2023/10/04 04:18:39.308 050688 000023e8     >Hex dump of windowState:
    00000048 2023/10/04 04:18:39.308 050688 000023e8     >0000000003737FF0:  000000FF 00000000 FD000000 02000000  ................
    00000049 2023/10/04 04:18:39.308 050688 000023e8     >0000000003738000:  00000001 22000002 00FC0200 000001FB  ...."...........
    00000050 2023/10/04 04:18:39.308 050688 000023e8     >0000000003738010:  00000016 00450078 0070006C 006F0072  .....E.x.p.l.o.r
    00000051 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738020:  00650072 00420061 00720100 00000000  .e.r.B.a.r......
    00000052 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738030:  00020000 0001C600 07FFFF00 00000300  ................
    00000053 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738040:  00027100 00009CFC 01000000 01FB0000  ..q.............
    00000054 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738050:  00160050 00690063 00740075 00720065  ...P.i.c.t.u.r.e
    00000055 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738060:  004C0069 00730074 01000001 28000002  .L.i.s.t....(...
    00000056 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738070:  71000002 7100FFFF FF000002 71000001  q...q.......q...
    00000057 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738080:  5E000000 01000000 04000000 01000000  ^...............
    00000058 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738090:  08FC0000 0000        
    
    Pl45m4P 1 Reply Last reply
    0
    • PerdrixP Perdrix

      My application saves the geometry and state in my closeEvent handler:

      	QSettings settings;
      	settings.beginGroup("MainWindow");
      	auto geometry{ saveGeometry() };
      	settings.setValue("geometry", geometry);
      #ifndef NDEBUG	
      	ZTRACE_RUNTIME("Hex dump of geometry:");
      	ZTrace::dumpHex(geometry.constData(), geometry.length());
      #endif 
      
      	auto windowState{ saveState()};
      	settings.setValue("windowState", saveState());
      #ifndef NDEBUG	
      	ZTRACE_RUNTIME("Hex dump of windowState:");
      	ZTrace::dumpHex(windowState.constData(), windowState.length());
      #endif
      
      	settings.endGroup();
      

      When I reopen the application I do this in the main window startup code:

      	QSettings settings;
      	settings.beginGroup("MainWindow");
      
      	auto geometry{ settings.value("geometry", QByteArray()).toByteArray() };
      	auto windowState{ settings.value("windowState", QByteArray()).toByteArray() };
      
      #ifndef NDEBUG
      	if (geometry.length())
      	{
      		ZTRACE_RUNTIME("Hex dump of geometry:");
      		ZTrace::dumpHex(geometry.constData(), geometry.length());
      	}
      	if (windowState.length())
      	{
      		ZTRACE_RUNTIME("Hex dump of windowState:");
      		ZTrace::dumpHex(windowState.constData(), windowState.length());
      	}
      #endif
      
      	restoreGeometry(geometry);
      	restoreState(windowState);
      	settings.endGroup();
      

      This works most of the time, but if I maximise the application and then close it the window opens at the top left of the desktop with a relatively small size (1152 x 698) rather than maximised.

      What am I doing wrong please. I am sure it used to work on Qt 6.4.0 (this is 6.5.1)

      The hex dump of the window geometry and state at close time was:

      00000041 2023/10/04 04:18:39.307 050688 000023e8     >Hex dump of geometry:
      00000042 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822760:  01D9D0CB 00030000 00000000 FFFFFFF9  ................
      00000043 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822770:  00000398 0000022C 00000000 00000017  .......,........
      00000044 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822780:  00000398 0000022C 00000000 00000000  .......,........
      00000045 2023/10/04 04:18:39.307 050688 000023e8     >0000000003822790:  0C000000 00000000 00170000 03980000  ................
      00000046 2023/10/04 04:18:39.308 050688 000023e8     >00000000038227A0:  022C                                 .,              
      00000047 2023/10/04 04:18:39.308 050688 000023e8     >Hex dump of windowState:
      00000048 2023/10/04 04:18:39.308 050688 000023e8     >0000000003737FF0:  000000FF 00000000 FD000000 02000000  ................
      00000049 2023/10/04 04:18:39.308 050688 000023e8     >0000000003738000:  00000001 22000002 00FC0200 000001FB  ...."...........
      00000050 2023/10/04 04:18:39.308 050688 000023e8     >0000000003738010:  00000016 00450078 0070006C 006F0072  .....E.x.p.l.o.r
      00000051 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738020:  00650072 00420061 00720100 00000000  .e.r.B.a.r......
      00000052 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738030:  00020000 0001C600 07FFFF00 00000300  ................
      00000053 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738040:  00027100 00009CFC 01000000 01FB0000  ..q.............
      00000054 2023/10/04 04:18:39.309 050688 000023e8     >0000000003738050:  00160050 00690063 00740075 00720065  ...P.i.c.t.u.r.e
      00000055 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738060:  004C0069 00730074 01000001 28000002  .L.i.s.t....(...
      00000056 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738070:  71000002 7100FFFF FF000002 71000001  q...q.......q...
      00000057 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738080:  5E000000 01000000 04000000 01000000  ^...............
      00000058 2023/10/04 04:18:39.310 050688 000023e8     >0000000003738090:  08FC0000 0000        
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Perdrix

      What OS are you using?

      Note this from here:

      On X11, this might not work because an invisible window does not have a frame yet. The window manager will decorate the window later. When this happens, the window shifts towards the bottom/right corner of the screen depending on the size of the decoration frame. Although X provides a way to avoid this shift, some window managers fail to implement this feature.

      In addion, it seems that there are a lot of bugs when trying to restore geometry from settings. There are also some workarounds

      • https://stackoverflow.com/questions/15111788/qwidgetsave-restoregeometry-loses-window-size-if-maximized-bug-or-feature
      • https://stackoverflow.com/questions/44005852/qdockwidgetrestoregeometry-not-working-correctly-when-qmainwindow-is-maximized

      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
      0
      • PerdrixP Perdrix has marked this topic as solved on

      • Login

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