In this tutorial, I am going to show you how to save your #PyQt5 application settings with #QSettings class.

When you create a desktop application, normally you want to have a “preference” option allowing users to save application settings such as window size, last closed position, font style, background color, etc, so next time when the user re-open the application, all the configurations will resume to the last session.

I will be using Windows 10 for the demonstration. The settings I want to save are window size and last closed position.

Buy Me a Coffee? Your support is much appreciated!
PayPal Me:
Venmo: @Jie-Jenn

Source Code:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QSettings

class MyApp(QWidget):
    def __init__(self):

        self.settings = QSettings('MyQtApp', 'App1')
        # print(self.settings.fileName())
            self.reisze(self.settings.value('window size'))
            self.move(self.settings.value('window position'))

    def closeEvent(self, event):
        self.settings.setValue('window size', self.size())
        self.settings.setValue('window position', self.pos())

app = QApplication(sys.argv)        

demo = MyApp()