def saveState(self):
settings = QSettings('gui.ini', QSettings.Format.IniFormat)
for type, method in self._get_saving_types():
for widget in self.findChildren(type):
if isinstance(widget, QListWidget):
items = []
for index in range(widget.count()):
item = widget.item(index)
item_data = {
'text': item.text(),
'checked': item.checkState() == Qt.Checked
}
items.append(item_data)
settings.setValue(widget.objectName(), items)
else:
settings.setValue(widget.objectName(), methodcaller(method[1])(widget))
def loadState(self):
settings = QSettings('gui.ini', QSettings.Format.IniFormat)
for type, method in self._get_saving_types():
for widget in self.findChildren(type):
if settings.contains(widget.objectName()):
if isinstance(widget, QListWidget):
items_data = settings.value(widget.objectName(), [])
widget.clear()
for item_data in items_data:
item = QListWidgetItem(item_data['text'])
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
if item_data['checked']:
item.setCheckState(Qt.Checked)
else:
item.setCheckState(Qt.Unchecked)
widget.addItem(item)
else:
methodcaller(method[0], settings.value(widget.objectName()))(widget)