有没有一种方法可以检查QSettings是否使用默认值?
例如:
def setup_ui(self):
self.user_input = QtGui.QLineEdit()
self.user_input.setText("Input something...")
...
...
# Check for any stored settings
self.user_input.setText(self.settings.value("userInput", "Input something..."))
def load_settings(self):
self.settings = QtCore.QSettings('TEST', 'My_Tool')
input = self.settings.value("userInput", "Input something...")
def save_settings(self):
settings = QtCore.QSettings('TEST', 'My_Tool')
settings.setValue('userInput', self.user_input.currentText())
如果我重新启动我的工具,则某些功能将使用QLineEdit中的当前文本字符串。到目前为止,为了绕过默认值,我对函数进行了如下编码:
def test_func(self, input_text):
if not input_text == 'Input something...':
# Do something...
答案 0 :(得分:0)
您的问题等同于询问密钥是否存在,因此您必须使用contains()
方法:
if settings.contains("userInput"):
# there is the key in QSettings
else:
# there is no key in QSettings