[solved] Reset MainWindow to default geometry



  • 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



  • 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());
    }@



  • 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?



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.