PDA

View Full Version : Fixing default Window position with move.



VireX
3rd April 2007, 17:58
Ok, I used QSettings to save the QPoint of where the user left the window before closing the window.

When I relaunch the program, it does remember the last location the user kept the window, but it seems to add like 20 pixels to the Y position, so if I have a window maximized, after I close the program, the next time the program will be 20 pixels above where I last saved.

I'm thinking it has something to do with my resolution. Is there a way to adjust it so, that it should stay exactly where the user saved according to their screen?
like GetSystemMetrics kinda thing in Win API.

I tried using: mapToGlobal(ptPos);
But that's not what I want, it makes it relative to the top left of widget.

I tried manually adjusting the Y, each time I call the settings. But that's usually a wrong offset, and not a good fix.

jpn
3rd April 2007, 18:04
Are you using Qt 4.2? Maybe QWidget::restoreGeometry() and QWidget::saveGeometry() would be sufficient for you?

VireX
3rd April 2007, 18:19
like this?


Array = saveGeometry();
settings.setValue("geometry", Array);
// set the value on close.

//get value
qbaArray = settings.value("geometry", QByteArray("10,10,10,10")).toByteArray();
restoreGeometry(qbaArray);


I don't believe it worked. I am using 4.2.2
Also, how did people do it before this method?

jpn
3rd April 2007, 18:43
like this?


Array = saveGeometry();
settings.setValue("geometry", Array);
// set the value on close.

//get value
qbaArray = settings.value("geometry", QByteArray("10,10,10,10")).toByteArray(); // <-- faulty
restoreGeometry(qbaArray);


I don't believe it worked. I am using 4.2.2

Sorry, what do you mean by "I don't believe it worked"? Does it work or not? :)

Actually, the following is a bit faulty. QWidget uses more complex bytearray content for storing the geometries. QWidget validates the content of the passed byte array, though.

qbaArray = settings.value("geometry",
QByteArray("10,10,10,10")).toByteArray();


Also, how did people do it before this method?
More or less how it's done in Window Geometry documentation (http://doc.trolltech.com/4.2/geometry.html). ;) The more states (minimized, maximized, full screen) you want to take into, the more complex it gets. That's why QWidget::restoreGeometry() and QWidget::saveGeometry() were introduced.

VireX
3rd April 2007, 22:13
I think it worked, I didn't believe because my program was crashing, so I didn't know if it was the geometry, or something else I had changed. It wasn't the geometry.