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. [solved] Reset MainWindow to default geometry
Forum Update on Tuesday, May 27th 2025

[solved] Reset MainWindow to default geometry

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 22 Jun 2014, 10:31 last edited by
    #1

    Hi there!
    I'm having a rather complex UI with floatable Docks and other stuff. It's state is automatically saved using QSettings with saveState (at destructor). Of course it's also auto-loaded at the constructor.
    Now, if my poor user completely messes up the interface, I want to let him restore everything to default withone click, so that he won't despair in his self-made chaos. For that purpose, the MainWindow is to be equipped with a slot connected to a QAction (callable from the Window Menu).
    And now I don't know what to write into this slot. Appearently, restoreState(NULL); or restoreState(QByteArray()); does not work. How do I do that?
    Cheers,
    Kalsan

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 22 Jun 2014, 11:09 last edited by
      #2

      I have called the following two slots based on some actions. In your case you call saveme() in the constructor itself. You need to store the data somehow.

      Post this you call restoreme() based on some menu click.

      @void MainWindow::saveme(){
      qDebug() << "Save me" << endl;
      QSettings settings("MyCompany", "pthinks.com");
      settings.setValue("geometry", saveGeometry());
      settings.setValue("windowState", saveState());
      }

      void MainWindow::restoreme(){
      qDebug() << "Restore me" << endl;
      QSettings settings("MyCompany", "pthinks.com");
      restoreGeometry(settings.value("geometry").toByteArray());
      restoreState(settings.value("windowState").toByteArray());
      }@

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on 22 Jun 2014, 12:07 last edited by
        #3

        Thanks for your reply! I'm having a little trouble understanding it. Do you mean mean the following with that?:
        -> There is no such reset function
        -> Therefore I shall save the default state somewhere before loading settings
        -> When resetting the state, just load it from there
        Is that what your point is? If yes, would it be a good idea to just store the state into a QByteArray that is part of mainwindow.h?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 22 Jun 2014, 12:27 last edited by
          #4

          No reset. You need store the settings what you want.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on 22 Jun 2014, 16:05 last edited by
            #5

            Well with "reset" I meant restoring the defaults. I guess we're talking about the same thing.
            Thanks, I'll do that!

            1 Reply Last reply
            0

            1/5

            22 Jun 2014, 10:31

            • Login

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