PDA

View Full Version : How to use QSetting for different resolutions.



pastispast
7th October 2010, 17:58
Hi Friends,

I am using QmainWindow with tool bar and the dockwidgets. I have used QSetting to save and load the state.

But I am facing one problem:

- I have saved my window layout with some resolution (say 1280 X 1024) then I am able to retrieve it while loading. But when the system resolution is set other then the previous one (say 800 X 600) then I am not able to retrieve the proper format. Same happen vice verse...

What I am missing??? I have used save setting and load setting as:



void MyMainWindow::writeSettings()
{
QSettings settings("workspace/myapp.ini", QSettings::IniFormat);

settings.beginGroup("MyMainWindow");

settings.setValue("geometry", saveGeometry());
settings.setValue("state", saveState());

settings.sync();

settings.endGroup();
}

void MyMainWindow::readSettings()
{
//QSettings settings("SKU", "MY Main Window");
QSettings settings("workspace/myapp.ini", QSettings::IniFormat);

settings.beginGroup("MyMainWindow");

restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("state").toByteArray());

settings.endGroup();
}


Note: I am using frame less window (It's a need).


Thanks...

ChrisW67
8th October 2010, 00:40
From QWidget::restoreGeometry():

If the restored geometry is off-screen, it will be modified to be inside the available screen geometry.


You cannot fit a window sized at 1280x1024 into 800x600 without changing anything so it's likely that Qt is resizing/moving to fit. It is not clear from your post exactly what "proper format" should be. If your layout becomes unusable at 800x600 then you need to address this (or set a lower screen-size limit) with layout management and scroll areas etc.

pastispast
8th October 2010, 14:19
From QWidget::restoreGeometry():


You cannot fit a window sized at 1280x1024 into 800x600 without changing anything so it's likely that Qt is resizing/moving to fit. It is not clear from your post exactly what "proper format" should be. If your layout becomes unusable at 800x600 then you need to address this (or set a lower screen-size limit) with layout management and scroll areas etc.

Hi ChrisW67, Thanks for the reply.

Actually I have 3 dockwidget in my application.

1- MainDock
2- Left
3- Bottom

I have given more space to the "MainDock" [around 3/4 * width() and 3/4 * height()].

But while saving it using "writeSettings(...)" function in resolution "1280x1024" and opening the application in "800 x 600", I did not found the spacing what I have saved in the "1280x1024" resolution [At least ratio wise]

Is there any way to maintain the layout using QSetting for different resolutions.

SixDegrees
8th October 2010, 14:26
QSettings doesn't have a brain; it only stores positions and sizes. When you make the geometry calls, they're smart enough to place things so they're still onscreen, but that's the limit of their intelligence.

If you want to duplicate your original layout at a different size, you'll have to retrieve the raw settings and do the computations yourself. Qt's QRect class and related ones can help here.