1
votes

I save and restore a QMainWindow's size and position as follows:

window->resize(savedSize);
window->move(savedPos);
window->show();

void closeEvent(QCloseEvent *e) {
    savedSize = window->size();
    savedPos = window->pos();
}

The problem is that the window position is changed by the applications bar (the bar where the Windows minimize and maximize buttons are). So when I open and close the window a few times then the window moves more and more down (each time exactly the size of the application bar). How can I exactly restore the last position?

Regards,

1

1 Answers

2
votes

You should use QWidget::saveGeometry() to get the window size and QWidget::restoreGeometry() to restore it, for instance with QSetting. You may be interested also in QMainWindow::saveState() and QMainWindow::restoreState()