PDA

View Full Version : I need help resizing QDockWidgets Mannually



aarelovich
22nd June 2010, 16:32
Hi:

I have problems setting the geometry of QDockWidgets manually. Here is the two concerning functions:


void MineEdit::SaveSettings(){
ui->dwErrorList->setVisible(false);
QSettings settings("settings",QSettings::IniFormat);
settings.setValue("exists",1);
settings.setValue("windowsizes/window",this->geometry());
settings.setValue("windowsizes/logger",ui->dwLog->geometry());
settings.setValue("windowsizes/editor",ui->dwEditor->geometry());
qDebug() << "Setting editor geometry to" << ui->dwEditor->geometry();
settings.setValue("windowsizes/rwords",ui->dwWords->geometry());
settings.setValue("windowsizes/isRwordsVisible",ui->dwWords->isVisible());
settings.setValue("documents/lastdoc",CurrentDoc);
}

bool MineEdit::ReloadSettings(){
QSettings settings("settings",QSettings::IniFormat);
if (settings.value("exists").toInt() == 1){
this->setGeometry(settings.value("windowsizes/window").toRect());
ui->dwLog->setGeometry(settings.value("windowsizes/logger").toRect());
ui->dwEditor->setGeometry(settings.value("windowsizes/editor").toRect());
qDebug() << "Restoring editor geometry to" << settings.value("windowsizes/editor").toRect();
ui->dwWords->setGeometry(settings.value("windowsizes/rwords").toRect());
ui->dwWords->setVisible(settings.value("windowsizes/isRwordsVisible").toBool());
CurrentDoc = settings.value("documents/lastdoc").toString();
return true;
}
return false;
}

The function save settings is called when the program closes. While Reload is called in the main class's constructor.
The problem is that the code correctly saves the dimensions I save for the dockwidget and it also correctly loads them. However they are not applied.

My lay out looks like the image that says editor_when_open. I modify it to look like it shows in editor_when_modified and when I close and open my app again it looks like editor_when_open again even though the qDebug says that it saves and restores the modifed geometry.

What am I doing wrong?

Thanks for any answers

high_flyer
22nd June 2010, 16:47
you have to call ReloadSettings() after the MainWindow is visible.

aarelovich
22nd June 2010, 17:39
Ok, that was my theory.

However it does not work if I call it during resizeEvent either. So what event should I redefine?

Thank you.

aarelovich
22nd June 2010, 18:24
Problem Solved!

I used QMainWindow::[restore/save]State() and QMainWindow::[restore/save]Geometry() instead of setting each value manually. And I still called the RestoreSettings in the constructor.

Thanks for all the help!