Results 1 to 8 of 8

Thread: Save and restore maximized state

  1. #1
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Save and restore maximized state

    Hello all

    Currently using Qt 4.8.2 X64 on Windows, but I also tried it on 4.8.1 on a debian machine.

    I'm wondering how you save the maximized state and restore it properly. Currently I save the position and size when closing and restore that when starting again, but this doesn't work all that well. The window looks maximized (the size is correct) but it's a little out of position and not really in maximized state (you can press the maximize button again).

    Code isn't much, saving would be:

    Qt Code:
    1. QSettings settings(COMPANY_NAME, PRODUCT_NAME);
    2. settings.setValue("pos", pos());
    3. settings.setValue("size", size());
    To copy to clipboard, switch view to plain text mode 

    Restoring would be:
    Qt Code:
    1. QSettings settings(COMPANY_NAME, PRODUCT_NAME);
    2. QPoint pos = settings.value("pos", QPoint(100, 100)).toPoint();
    3. QSize size = settings.value("size", QSize(1024, 600)).toSize();
    4. resize(size);
    5. move(pos);
    To copy to clipboard, switch view to plain text mode 

    I also tried the saveGeometry() and restoreGeometry() functions. This works, except for a problem on a dual screen system where the window is maximized on the wrong screen (the default screen) at startup. So I thought I'd simply save the maximized state with isMaximized() as a bool and restore it with showMaximized(), but had similar results as well. Other 3rd party applications (e.g. visual studio) do this correct on my system.

    So what is the correct way of doing this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Save and restore maximized state

    I would store isMaximized() and then call showMaximized() while restoring (instead of setting the size and position).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save and restore maximized state

    Thanks for the reply. As mentioned above, that is one of the things I've tried (see the bottom of my first post). But it results in the program starting maximized on the wrong screen.

    Anyone with other ideas on how to solve it?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Save and restore maximized state

    So move it to the proper screen first.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save and restore maximized state

    Yes I know that, but that is the question though. How do I detect the screen I'm on so I can save that information, and how do I move to the correct screen when restoring?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Save and restore maximized state

    Use QDesktopWidget API.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2012
    Posts
    37
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Save and restore maximized state

    Thanks, that will solve it!

  8. #8
    Join Date
    Sep 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Save and restore maximized state

    This bug appears with Qt 4.8.0 version.
    You should vote in qt bug tracker, and hope will be solved a day.......
    https://bugreports.qt-project.org/browse/QTBUG-21371
    It' s not a severe bug, but it's annoying, for exampel Qt designer is never restored on 2nd screen if in maximized state...

Similar Threads

  1. Replies: 0
    Last Post: 31st May 2012, 11:33
  2. save and restore TreeWidgetItem
    By raj_iv in forum Newbie
    Replies: 3
    Last Post: 26th August 2011, 09:12
  3. Save & Restore a selection in QTreeWidget
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 20:54
  4. QPainter save() and restore()
    By babu198649 in forum Newbie
    Replies: 4
    Last Post: 28th July 2008, 10:22
  5. Replies: 5
    Last Post: 9th May 2007, 22:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.