Created
February 2, 2016 10:42
-
-
Save studiofuga/94c91b4678049fd42024 to your computer and use it in GitHub Desktop.
Qt MainWindow state and position save/restore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MainWindow::MainWindow(QWidget *parent) : | |
QMainWindow(parent), | |
ui(new Ui::MainWindow) | |
{ | |
ui->setupUi(this); | |
// ... | |
QSettings settings; | |
restoreGeometry(settings.value("geometry").toByteArray()); | |
restoreState(settings.value("windowState").toByteArray()); | |
} | |
void MainWindow::closeEvent(QCloseEvent *event) | |
{ | |
if (QMessageBox::question(this, tr("Close"), tr("Do you want to close this Window?"), QMessageBox::No, QMessageBox::Yes) == QMessageBox::No) { | |
event->ignore(); | |
return; | |
} | |
QSettings settings; | |
settings.setValue("geometry", saveGeometry()); | |
settings.setValue("windowState", saveState()); | |
QMainWindow::closeEvent(event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment