I'm currently writing an application in PySide, and I want it to save the window dimensions upon exiting. The geometry()
method retuns something like PySide.QtCore.QRect(300, 300, 550, 150)
but all I want is (300, 300, 550, 150)
. I could find a way to parse it, but I want a cleaner method. Any suggestions?
The cleaner way, without any parsing, would be to use QSettings
to store and retrieve the QRect
returned by geometry to/from the native application settings storage (Windows registry, .ini file, .plist file...).
For example:
settings = QSettings(...);
settings.setValue("lastGeometry", self.geometry())
# and to retrieve the value
lastGeometry = settings.value("lastGeometry")
if lastGeometry.isValid():
self.setGeometry(lastGeometry)
You can also binary serialize or deserialize a QRect
with QDataStream
to a 16 byte array representing the 4 32-bit integers.