Skip to content

Instantly share code, notes, and snippets.

@ksvbka
Last active September 13, 2019 06:58
Show Gist options
  • Save ksvbka/1f3e891fc07bc9a010c7cad4598777b7 to your computer and use it in GitHub Desktop.
Save ksvbka/1f3e891fc07bc9a010c7cad4598777b7 to your computer and use it in GitHub Desktop.
pyqt5: QSettings demo
#! /usr/bin/python3
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import QCoreApplication, QSettings
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
settings = QSettings()
self.list = settings.value('list', ['a', 'b', 'c'])
self.dict = settings.value('dict', {'key': 0})
self.str = settings.value('string', 'str')
self.int = settings.value('interger', 0, int)
print("list: ", self.list)
print("dict: ", self.dict)
print("string:", self.str)
print("interger:", self.int)
# Change value for testings
self.list.append(len(self.list))
self.str = self.str + str(len(self.list))
self.int = self.int + 1
self.dict[self.str] = self.int
def closeEvent(self, event):
settings = QSettings()
settings.setValue('list', self.list)
settings.setValue('dict', self.dict)
settings.setValue('string', self.str)
settings.setValue('interger', self.int)
if __name__ == '__main__':
QCoreApplication.setOrganizationName('org_name')
QCoreApplication.setOrganizationDomain('org_domain')
QCoreApplication.setApplicationName('app_name')
import sys
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment