输入一个spinBox
数字,保存在.ini文件中。重新启动程序后,这个数字进入Dial
笔的输入,操作范围从0
到10
。手柄的初始位置在中间,即 on5
并且也保存在.ini文件中。
句柄执行算术运算。例如,我们输入100
. 因此,输出应该从95
到接收数字105
。
如何使这个链接工作?
主文件
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.Exit.clicked.connect(self.close)
self.dial.setMinimum(0)
self.dial.setMaximum(10)
self.dial.setValue(5)
self.spinbox.setRange(1, 100)
self.spinbox.setValue(12)
self.load_settings()
def save_settings(self):
settings = QSettings(CONFIG_FILE_NAME, QSettings.IniFormat)
settings.setValue('BoolValue', int(self.cb_flag.isChecked()))
settings.setValue('DialValue', self.dial.value())
settings.setValue('SpinBoxValue', self.spinbox.value())
def load_settings(self):
settings = QSettings(CONFIG_FILE_NAME, QSettings.IniFormat)
self.cb_flag.setChecked(bool(int(settings.value('BoolValue', 0))))
self.dial.setValue(int(settings.value('DialValue', 0)))
self.spinbox.setValue(int(settings.value('SpinBoxValue', 0)))
def closeEvent(self, event):
self.save_settings()
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 class="QSpinBox" name="spinbox">
<property name="geometry">
<rect>
<x>330</x>
<y>40</y>
<width>111</width>
<height>22</height>
</rect>
</property>
</widget>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
我不知道我是否理解正确,但试试这个:
更新