在这段代码中,我已经掌握了在按下“”按钮时将值保存checkBox
在.iniВыход
文件中。
代码中需要添加什么来保存调节器的位置Dial
?
主文件
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.Qt import QSettings
from PyQt5.uic import loadUi
CONFIG_FILE_NAME = 'config.ini'
class New(QMainWindow):
def __init__(self):
super(New, self).__init__()
loadUi("checkBox_Dial_save.ui", self)
self.load_settings()
self.Exit.clicked.connect(self.ExitClicked)
self.dial.setMinimum(0)
self.dial.setMaximum(10)
self.dial.setValue(5)
def save_settings(self):
settings = QSettings(CONFIG_FILE_NAME, QSettings.IniFormat)
settings.setValue('BoolValue', int(self.cb_flag.isChecked()))
def load_settings(self):
settings = QSettings(CONFIG_FILE_NAME, QSettings.IniFormat)
self.cb_flag.setChecked(bool(int(settings.value('BoolValue', 0))))
def ExitClicked(self):
self.save_settings()
sys.exit()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = New()
window.show()
sys.exit(app.exec_())
checkBox_Dial_save.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>800</width>
<height>600</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<widget class="QWidget" name="centralwidget">
<property name="minimumSize">
<size>
<width>800</width>
<height>600</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>800</width>
<height>600</height>
</size>
</property>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>761</width>
<height>95</height>
</rect>
</property>
<property name="title">
<string>GroupBox</string>
</property>
<widget class="QDial" name="dial">
<property name="geometry">
<rect>
<x>100</x>
<y>28</y>
<width>100</width>
<height>55</height>
</rect>
</property>
<property name="wrapping">
<bool>false</bool>
</property>
<property name="notchesVisible">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="cb_flag">
<property name="geometry">
<rect>
<x>12</x>
<y>63</y>
<width>81</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
<widget class="QPushButton" name="Exit">
<property name="geometry">
<rect>
<x>650</x>
<y>30</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>Выход</string>
</property>
</widget>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
与您所做的实际相同
checkBox
: