Saving Window Size State/bg

From Qt Wiki
< Saving Window Size State
Revision as of 07:25, 24 February 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


Български English

Запаметяване на състоянието на прозорец

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 />}