QT恢复上一次窗口退出状态,代码

void MainWindow :: readSetting ()
{
    QSettings settings("1321235", "123");
    QRect geom = this->rect();
    QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
    QSize sz = settings.value("size", QSize(2 * geom.width() / 3, 2 * geom.height() / 3)).toSize();

    move(pos);
    resize(sz);
}

void MainWindow::writSetting()
{
    QSettings settings("1321235", "123");
    settings.setValue("pos", pos());
    settings.setValue("size", size());
}

void MainWindow::closeEvent(QCloseEvent* event)
{
    writSetting();
}

使用QSetting记录上次窗口退出大小位置,窗口关闭时执行writeSetting()函数,在界面构造函数里执行readSetting()函数;


                
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页