4

Is there any easy way to open the Qt dialogs in the same position as they were the last time the application was open ?
i.e. preserve position of dialogs between application sessions ?

By easy way I mean not to have manually write the window position in file, and then read :)

ymoreau
  • 3,402
  • 1
  • 22
  • 60
user152508
  • 3,053
  • 8
  • 38
  • 58

3 Answers3

10

You can use the QSettings class to achieve this. It's an abstraction class that allow your applications to store its settings in order to retrieve them at next launch.

Save settings:

QSettings settings("ValueName",  "Value");

Read settings:

QString v = settings.value("ValueName");
Patrice Bernassola
  • 14,136
  • 6
  • 46
  • 59
  • 2
    There is even an example of how to do this in the Qt documentation, at http://doc.trolltech.com/4.5/qsettings.html#restoring-the-state-of-a-gui-application – gnud Oct 08 '09 at 15:30
  • Yes it is on the same page that the QSettings class representation – Patrice Bernassola Oct 08 '09 at 15:33
3

Use QSettings along with QWidget::restoreGeometry() and QWidget::saveGeometry().

larsmoa
  • 12,604
  • 8
  • 62
  • 85
2

Better to save dialog->pos(), dialog->size(), dialog->isMaximized(), cause dialog->saveGeometry() doesn't maximize the window.

QSettings is the preffered way to save configuration

Pavels
  • 1,256
  • 1
  • 12
  • 19