简体   繁体   中英

Restore Qt Window size and position problem

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,

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM