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. Proper way to restore state/geometry on application start?
QtWS25 Last Chance

Proper way to restore state/geometry on application start?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • P Offline
    P Offline
    pmh4514
    wrote on last edited by pmh4514
    #1

    My QWidgets application (MainWindow with a central widget and surrounding dock widgets) uses saveGeometry() and saveState() to store window layout in QSettings.. I've added menu options for "Save Layout" and "Restore Layout" and they work just fine.

    The problem is, I want to restore layout on application startup, and it doesn't seem to quite work. I'm unsure where the best place to call it is. It seems my application loads, and things are "close" to where they were in terms of size and position, but not quite.. Once the application is loaded and the main window is visible, if the user chooses the "Restore Layout" menu option, the layout is restored properly. But I don't want the user to have to do this by hand once the application is open, it should be automatic. I tried extending the showEvent to call my restore layout method, but that didn't work.

    EDIT: I have found that if I the main window is not "maximized" then my automatic restoration of geometry and state (called just prior to win->show() ) works properly.. However, if the saved state is based on a maximized main-window, then I encounter my problems.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      Don't restore prior to show. You should rather trigger the restoration after that. One way would be to start a single shot QTimer at the end of the constructor with a 0 delay. That way the restoration will happen when the event loop start running and you should get better results.

      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
      2
      • P Offline
        P Offline
        pmh4514
        wrote on last edited by
        #3

        brilliant! that seems to work well.

        thank you!

        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