Fixing default Window position with move.
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.
Re: Fixing default Window position with move.
Are you using Qt 4.2? Maybe QWidget::restoreGeometry() and QWidget::saveGeometry() would be sufficient for you?
Re: Fixing default Window position with move.
like this?
Code:
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?
Re: Fixing default Window position with move.
Quote:
Originally Posted by
VireX
like this?
Code:
Array = saveGeometry();
settings.setValue("geometry", Array);
// set the value on close.
//get value
qbaArray
= settings.
value("geometry",
QByteArray("10,10,10,10")).
toByteArray();
// <-- faultyrestoreGeometry(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.
Code:
qbaArray = settings.value("geometry",
Quote:
Also, how did people do it before this method?
More or less how it's done in Window Geometry documentation. ;) 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.
Re: Fixing default Window position with move.
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.