title: QSettings(): How to save to current working directory
body: <p>For an app that can be run directly from a flash/pen/usb/jump/thumb drive, for portability in moving from one machine to another it can make sense for user settings to be stored on the memory stick in the same directory that the program is being run from (rather than Windows/Mac/Linux user or system dirs per machine).</p>
  
  <p>QSettings() is handy, however, can it be told to use the current working directory?</p>
  
  <p>Here's a little example program that keeps its screen position from run to run using QSettings():</p>
  
  <pre><code>from PySide import QtGui, QtCore
  from PySide.QtGui import QTabWidget, QApplication
  from PySide.QtCore import QSettings
  
  class AbcApp(QTabWidget):
      def __init__(self):
          super(AbcApp, self).__init__()
  
          self.settings = QSettings(QSettings.IniFormat,QSettings.SystemScope, '__MyBiz', '__settings')
          self.settings.setFallbacksEnabled(False)    # File only, not registry or or.
  
          # setPath() to try to save to current working directory
          self.settings.setPath(QSettings.IniFormat,QSettings.SystemScope, './__settings.ini')
  
          # Initial window size/pos last saved
          self.resize(self.settings.value("size", QtCore.QSize(270, 225)))
          self.move(self.settings.value("pos", QtCore.QPoint(50, 50)))
  
          self.tab = QtGui.QWidget()
          self.textEdit = QtGui.QTextEdit(self.tab)
          self.textEdit.setHtml('&lt;font color=grey&gt;[QTextEdit area]&lt;/font&gt;&lt;p&gt;&lt;center&gt;&lt;font color=blue size=4&gt;&lt;b&gt;Allo Woyld&lt;/b&gt;&lt;/font&gt;&lt;/center&gt;')
          self.addTab(self.tab, 'tab1')
  
      def closeEvent(self, e):
          # Write window size and position to config file
          self.settings.setValue("size", self.size())
          self.settings.setValue("pos", self.pos())
  
          e.accept()
  
  if __name__ == '__main__':
      app = QApplication('')
      frame = AbcApp()
      frame.show()
      app.exec_()
  </code></pre>
  
  <p>This .ini file is created since I happen to be running on Windows at the moment: <em>C:\Documents and Settings\All Users\Application Data__MyBiz__settings.ini</em>.</p>
  
  <p>UserScope instead of SystemScope does not help.<br>
  <code>'.'</code> instead of <code>'./__settings.ini'</code> did not work, setPath() basicaly no effect.<br>
  Also tried this to no avail:</p>
  
  <pre><code>filepath = os.getcwd() + '/__settings.ini'
  self.settings.setPath(QSettings.IniFormat,QSettings.SystemScope, filepath)
  </code></pre>
  
  <p>Reference: <a href="https://doc.qt.io/archives/qt-4.8/qsettings.html" rel="nofollow noreferrer">https://doc.qt.io/archives/qt-4.8/qsettings.html</a>
  <a href="http://www.pyside.org/docs/pyside/PySide/QtCore/QSettings.html" rel="nofollow noreferrer">http://www.pyside.org/docs/pyside/PySide/QtCore/QSettings.html</a></p>
  
  <p>Promising though I don't know how to adapt to PySide:<br>
  <a href="http://www.qtcentre.org/archive/index.php/t-35287.html" rel="nofollow noreferrer">http://www.qtcentre.org/archive/index.php/t-35287.html</a></p>
  
  <hr>
  
  <p>Update:  The answer from alexisdm works, so here's the updated code now:</p>
  
  <pre><code>from PySide import QtGui, QtCore
  from PySide.QtGui import QTabWidget, QApplication
  from PySide.QtCore import QSettings
  
  class AbcApp(QTabWidget):
      def __init__(self):
          super(AbcApp, self).__init__()
  
          self.settings = QSettings('settings.ini', QSettings.IniFormat)
          self.settings.setFallbacksEnabled(False)    # File only, no fallback to registry or or.
  
          # Initial window size/pos last saved if available
          self.resize(self.settings.value('size', QtCore.QSize(270, 225)))
          self.move(self.settings.value('pos', QtCore.QPoint(50, 50)))
  
          self.tab = QtGui.QWidget()
          self.textEdit = QtGui.QTextEdit(self.tab)
          self.textEdit.setHtml('&lt;font color=grey&gt;[QTextEdit area]&lt;/font&gt;&lt;p&gt;&lt;center&gt;&lt;font color=blue size=4&gt;&lt;b&gt;Allo Woyld&lt;/b&gt;&lt;/font&gt;&lt;/center&gt;')
          self.addTab(self.tab, 'tab1')
  
      def closeEvent(self, e):
          self.settings.setValue('size', self.size())
          self.settings.setValue('pos', self.pos())
          e.accept()
  
  if __name__ == '__main__':
      app = QApplication('')
      frame = AbcApp()
      frame.show()
      app.exec_()
  </code></pre>