QToolBar* initBar( const int type, QMainWindow* mw ){ QToolBar* bar = 0; QObject* wid = 0; switch ( type ) { /*another code*/ case MapToolBars::ContoursBar: bar = new QToolBar( mw ); wid = new ContoursToolbar( bar, mw ); bar->setCaption( QObject::tr( "Contours Toolbar" ) ); bar->setObjectName( "Contours Toolbar" ); break; /*another code*/ } if ( bar ) { mw->addToolBar( bar ); /*another code*/ } return bar;}
ContoursToolbar::ContoursToolbar( QToolBar* parent, QMainWindow* mw ) : QObject( parent ){ d = new ContoursToolbarPrivate; d->showSettings = new QAction( tr( "Contours Settings" ), parent ); d->showSettings->setIconSet( QPixmap( ":/contours.png" ) ); d->showSettings->setToggleAction( false ); d->showSettings->setStatusTip( tr( "Contours Settings" ) ); connect( d->showSettings, SIGNAL( activated() ), SLOT( showSettings() ) ); parent->addAction( d->showSettings ); d->dlg = new ContoursSettingsDialog( mw );}
void MainWindow::writeSettings(){ QSettings settings( ... ); settings.beginGroup( "Map" ); settings.setValue( "Geometry", saveGeometry() ); settings.setValue( "State", saveState() ); /*another code*/ settings.endGroup();}
void MainWindow::writeSettings(){ QSettings settings( ... ); settings.beginGroup( "Map" ); restoreGeometry( settings.setValue( "Geometry" ).toByteArray() ); restoreState( settings.setValue( "State" ).toByteArray() ); /*another code*/ settings.endGroup();}
MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags){ QSettings* settings = Helper::settings(); if(!restoreGeometry(settings->value("Window/geometry").toByteArray())) showMaximized();//... QDockWidget* navigationDockWidget = new QDockWidget(tr("Navigation"), this); navigationDockWidget->setObjectName("Navigation"); NavigationTree* navigationTree = new NavigationTree(navigationDockWidget); navigationDockWidget->setWidget(navigationTree); navigationDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); addDockWidget(Qt::LeftDockWidgetArea, navigationDockWidget, Qt::Vertical);//... mainToolBar = new QToolBar(tr("Main ToolBar"), this); mainToolBar->setObjectName("MainToolBar"); addToolBar(Qt::TopToolBarArea, mainToolBar); addToolBarBreak(Qt::TopToolBarArea);//... restoreState(settings->value("Window/state").toByteArray());}MainWindow::~MainWindow(){ QSettings* settings = Helper::settings(); settings->beginGroup("Window"); settings->setValue("geometry", saveGeometry()); settings->setValue("state", saveState()); settings->endGroup();}
QByteArray QSplitter::saveState () constbool QSplitter::restoreState ( const QByteArray & state )