Saving Window Size State

From Qt Wiki
Revision as of 09:34, 24 February 2015 by Maintenance script (talk | contribs)
Jump to navigation Jump to search


English Български

Saving Window Size State

class MainWindow : public QMainWindow<br />{<br /> Q_OBJECT

public:<br /> MainWindow(QWidget *parent = 0) : QMainWindow(parent) {<br /> QSettings settings;

restoreGeometry(settings.value(&quot;mainWindowGeometry&amp;quot;).toByteArray());

// create docks, toolbars, etc…

restoreState(settings.value(&quot;mainWindowState&amp;quot;).toByteArray());<br /> }

void closeEvent(QCloseEvent *event) {<br /> QSettings settings;<br /> settings.setValue(&quot;mainWindowGeometry&amp;quot;, saveGeometry());<br /> settings.setValue(&quot;mainWindowState&amp;quot;, saveState());<br /> }<br />};

int main(int argc, char *argv[])<br />{<br /> QApplication a(argc, argv);<br /> QCoreApplication::setOrganizationDomain(&quot;OrgDomain&amp;quot;);<br /> QCoreApplication::setOrganizationName(&quot;OrgName&amp;quot;);<br /> QCoreApplication::setApplicationName(&quot;AppName&amp;quot;);<br /> QCoreApplication::setApplicationVersion(&quot;1.0.0&amp;quot;);

MainWindow w;<br /> w.show();

return a.exec&amp;amp;#40;&amp;#41;;<br />}