How to remember last position and size (geometry) of PyQt application?

Santosh Kumar me at sntsh.com
Sun Nov 22 08:25:29 EST 2015


Hello all fellow Python programmers!

I am using PyQt5 (5.5.1) with Python 3.4.0 (64-bit) on Windows 8.1
64-bit. I don't think this much data was needed. :P

I am having trouble restoring the position and size (geometry) of my
very simple PyQt app.

What I read online is that this is the default behavior and we need to
use QSettings to save and retrieve settings from Windows registry,
which is stored in
`\\HKEY_CURRENT_USER\Software\[CompanyName]\[AppName]\`.

Here are some of the links are read:
http://doc.qt.io/qt-5.5/restoring-geometry.html
http://doc.qt.io/qt-5.5/qwidget.html#saveGeometry
http://doc.qt.io/qt-5.5/qsettings.html#restoring-the-state-of-a-gui-application
and the last one:
https://ic3man5.wordpress.com/2013/01/26/save-qt-window-size-and-state-on-closeopen/

I could have followed those tutorials but those tutorials/docs were
written for C++ users.

C++ is not my glass of beer. Should I expect help from you guys? :)

Here is minimal working application:


import sys
from PyQt5.QtWidgets import QApplication, QWidget

class sViewer(QWidget):
    """Main class of sViewer"""
    def __init__(self):
        super(sViewer, self).__init__()
        self.initUI()


    def initUI(self):
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    view = sViewer()
    sys.exit(app.exec_())



More information about the Python-list mailing list