title: How to save selected Items to Qsettings from QListWidget, QTableWidget
body: <p>I am Using PyQt5 and Py3.7, I am trying to loop through all my Qlistwidgets and save their string data, but also save all selected items on that widget. I slightly modified the loop from <a href="https://stackoverflow.com/questions/23279125/python-pyqt4-functions-to-save-and-restore-ui-widget-values">here</a>, but am having some trouble getting the selected items to save and restore using the listwidget array loop. I checked the docs but can't seem to understand how to add additional options into the array (such as save all selected items), from the Qt docs for SetArrayIndex, <a href="https://doc.qt.io/qtforpython/PySide2/QtCore/QSettings.html#PySide2.QtCore.PySide2.QtCore.QSettings.setArrayIndex" rel="nofollow noreferrer">here</a>.</p>
  
  <p>My listWidgets have selectionMode set to MultiSelection.
  I am currently saving using this:</p>
  
  <pre><code>def save_list_data(self):
      self.settings = QSettings("data.ini", QSettings.IniFormat)
      for name, obj in inspect.getmembers(self):
          if isinstance(obj, QListWidget):
              name = obj.objectName()
              self.settings.beginWriteArray(name)
              for i in range(obj.count()):
                  self.settings.setArrayIndex(i)
                  self.settings.setValue(name, obj.item(i).text())
              self.settings.endArray()
  </code></pre>
  
  <p>And then restoring the listWidget data using:</p>
  
  <pre><code>def open_list_data(self):
      self.settings = QSettings("data.ini", QSettings.IniFormat)
      for name, obj in inspect.getmembers(self):
          if isinstance(obj, QListWidget):
              name = obj.objectName()
              size = self.settings.beginReadArray(name)
              for i in range(size):
                  self.settings.setArrayIndex(i)
                  value = self.settings.value(name)
                  if value != None:
                      obj.addItem(value)
              self.settings.endArray()
  </code></pre>
  
  <p>This works fine for the data, but how can I get the selectedItems from the ListWidgets to save and restore as well?</p>