Just use a static variable in your dialog class, here is a complete sample app (using 4.8.x):
#include <QApplication>
#include <QDialog>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
class MyDialog : public QDialog
{
Q_OBJECT
public:
MyDialog(QWidget *parent = 0)
: QDialog(parent)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(new QLabel("Test Label"));
}
public Q_SLOTS:
virtual int exec() {
resize(s_dialogSize);
return QDialog::exec();
}
protected:
void closeEvent(QCloseEvent *event) {
Q_UNUSED(event)
s_dialogSize = size();
}
private:
static QSize s_dialogSize;
};
QSize MyDialog::s_dialogSize;
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
MyDialog dialog;
qDebug() << dialog.exec();
qDebug() << dialog.exec();
qDebug() << dialog.exec();
return app.exec();
}
#include "main.moc"
I've only implemented the closeEvent here, but if you want to save the size on accept/reject you need to save it to the variable in those methods as well (they are all virtual methods, and can be implemented in a similar fashion).