简体   繁体   English

恢复Qt窗口大小和位置问题

[英]Restore Qt Window size and position problem

I save and restore a QMainWindow's size and position as follows: 我保存并恢复QMainWindow的大小和位置,如下所示:

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). 问题在于,窗口位置由应用程序栏(Windows最小化和最大化按钮所在的栏)更改。 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. 您应该使用QWidget :: saveGeometry()获取窗口大小,并使用QWidget :: restoreGeometry()恢复窗口大小,例如使用QSetting。 You may be interested also in QMainWindow::saveState() and QMainWindow::restoreState() 您可能也会对QMainWindow :: saveState()和QMainWindow :: restoreState()感兴趣

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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