A
A
Artem Filimonov2017-07-14 11:41:09
Qt
Artem Filimonov, 2017-07-14 11:41:09

How to remember the settings of open dockWidgets in an application?

I have an application where DockWidget() is used,
so the question is how to call

void MainForm::closeEvent(QCloseEvent* event)
{
  writeSettigs();
  event->accept();
}

save and then restore settings?
void MainForm::writeSettigs()
{
  QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
  settings.setValue("geometry", saveGeometry());
}

void MainForm::readSettings()
{
  QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
  const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
  QPoint pos = settings.value("pos", QPoint(100, 100)).toPoint();
  
  if (geometry.isEmpty()) {
    const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
    resize(1200, 700);
    move(200, 200);
  }
  else {
    restoreGeometry(geometry);
    
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Filimonov, 2017-07-14
@Nvek

here is what i got

void MainForm::readSettings()
{

  //restoreState();

  QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
  const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
  //const QByteArray dock = settings.value("dockwidget", QByteArray()).toByteArray();
  const QByteArray mainWin = settings.value("mainwindow", QByteArray()).toByteArray();
  QMainWindow::restoreState(mainWin);

  /*dockData*/
  /*statCompareView*/
  settings.beginGroup("dockWidget");
  
  /**/settings.beginGroup("comparableviewer");
  /**//**/statCompareView->setVisible(settings.value("visible", true).toBool());
  /**//**/statCompareView->restoreGeometry(settings.value("geometry", QByteArray()).toByteArray());
  /**/settings.endGroup();
  
  /**/settings.beginGroup("treeview");
  /**//**/dockData->setVisible(settings.value("visible", true).toBool());
  /**//**/dockData->restoreGeometry(settings.value("geometry", QByteArray()).toByteArray());
  /**/settings.endGroup();
  //
  settings.endGroup();





  QPoint pos = settings.value("pos", QPoint(100, 100)).toPoint();
  if (geometry.isEmpty()) {
    const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
    resize(1200, 700);
    move(200, 200);
  }
  else {
    restoreGeometry(geometry);
    
  }
}

void MainForm::writeSettigs()
{
  QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
  settings.setValue("geometry", saveGeometry());
  settings.setValue("mainwindow", QMainWindow::saveState());


  settings.beginGroup("dockWidget");
  
  /**/settings.beginGroup("comparableviewer");
  /**//**/settings.setValue("visible", statCompareView->isVisible());
  /**//**/settings.setValue("geometry", statCompareView->saveGeometry());
  /**/settings.endGroup();
  
  /**/settings.beginGroup("treeview");
  /**//**/settings.setValue("visible", dockData->isVisible());
  /**//**/settings.setValue("geometry", dockData->saveGeometry());
  /**/settings.endGroup();

  settings.endGroup();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question