tags:

views:

186

answers:

3

I'm looking for a way to preserve the size of windows in a Qt app.

I've seen that there is the possibility of using the following method for every widget:

saveGeometry()

But really, I don't find this a satisfactioning method. Is there something like setAutosaveGeometry(True)?

I'm especially looking for a way to store the widths of table columns.

A: 

saveGeometry returns a QByteArray value, you need to store it somewhere.

Example:

void MainWindow::closeEvent(QCloseEvent *event){
    QSettings settings;

    settings.setValue("geometry", saveGeometry());
}

For reading the geometry call the restoreGeometry function:

MainWindow::MainWindow(QWidget *parent):QMainWindow(parent) {
    [...]

    QSettings settings;

    restoreGeometry(settings.value("geometry").toByteArray());

    [...]
}

To learn more about window geometry please read the documentation

xgoan
I knew that already. I'm looking for a way to restore the layout of a QTableView, not only the window geometry.
Georg
A: 

See the Qt documentation on Restoring a Window's Geometry.

Ariya Hidayat
This doesn't store the geometry of the children of the window. (Not all of them should be stored though…)
Georg
+2  A: 

The QHeaderView class also has two methods for saving and restoring it's state to and from a QByteArray: saveState()and restoreState()

A table view's headers are accessible via the horizontalHeader() and verticalHeader() methods.

IgKh