Saving Window Size State: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
[[Category:snippets]] | |||
'''English''' [[Saving_Window_Size_State_Bulgarian|Български]] | |||
= Saving Window Size State = | |||
<code>class MainWindow : public QMainWindow<br />{<br /> Q_OBJECT | |||
* [ | public:<br /> MainWindow(QWidget *parent = 0) : QMainWindow(parent) {<br /> QSettings settings; | ||
restoreGeometry(settings.value("mainWindowGeometry&quot;).toByteArray()); | |||
// create docks, toolbars, etc… | |||
restoreState(settings.value("mainWindowState&quot;).toByteArray());<br /> } | |||
void closeEvent(QCloseEvent *event) {<br /> QSettings settings;<br /> settings.setValue("mainWindowGeometry&quot;, saveGeometry());<br /> settings.setValue("mainWindowState&quot;, saveState());<br /> }<br />}; | |||
int main(int argc, char *argv[])<br />{<br /> QApplication a(argc, argv);<br /> QCoreApplication::setOrganizationDomain("OrgDomain&quot;);<br /> QCoreApplication::setOrganizationName("OrgName&quot;);<br /> QCoreApplication::setApplicationName("AppName&quot;);<br /> QCoreApplication::setApplicationVersion("1.0.0&quot;); | |||
MainWindow w;<br /> w.show(); | |||
return a.exec&amp;#40;&#41;;<br />}</code> |
Revision as of 09:34, 24 February 2015
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("mainWindowGeometry&quot;).toByteArray());
// create docks, toolbars, etc…
restoreState(settings.value("mainWindowState&quot;).toByteArray());<br /> }
void closeEvent(QCloseEvent *event) {<br /> QSettings settings;<br /> settings.setValue("mainWindowGeometry&quot;, saveGeometry());<br /> settings.setValue("mainWindowState&quot;, saveState());<br /> }<br />};
int main(int argc, char *argv[])<br />{<br /> QApplication a(argc, argv);<br /> QCoreApplication::setOrganizationDomain("OrgDomain&quot;);<br /> QCoreApplication::setOrganizationName("OrgName&quot;);<br /> QCoreApplication::setApplicationName("AppName&quot;);<br /> QCoreApplication::setApplicationVersion("1.0.0&quot;);
MainWindow w;<br /> w.show();
return a.exec&amp;#40;&#41;;<br />}