def updateDataDictionary(self, opt, idx, param, check):
"""Populates the ScrollArea for Storage Enabling on Hub basis
:param opt: Option tells what to modify: technology(0) or storage(1)
:type opt: Integer
:param idx: The id for the hub which needs to be modified
:type idx: String
:param param: The Technology/Storage which needs to be modified
:type param: String
:returns: None
:rtype: None
"""
if(check.isChecked()):
if(opt == 1):
self.data_dictionary[idx]["Technologies"][param]["Enabled"] = "1"
elif(opt == 2):
self.data_dictionary[idx]["Storages"][param]["Enabled"] = "1"
else:
if(opt == 1):
self.data_dictionary[idx]["Technologies"][param]["Enabled"] = "0"
elif(opt == 2):
self.data_dictionary[idx]["Storages"][param]["Enabled"] = "0"
for i in range(len(self.data_dictionary.keys())):
temp_check = QCheckBox()
temp_check.setText(str(self.data_dictionary.keys()[i]))
if(self.data_dictionary[self.data_dictionary.keys(
)[i]]["Technologies"][self.dock_tab3_1.techCombo.currentText(
)]["Enabled"] == "1"):
# Make the Checkbox checked
temp_check.setChecked(True)
else:
# Make the Checkbox un-checked
temp_check.setChecked(False)
temp_check.stateChanged.connect(partial(
self.updateDataDictionary, 1, self.data_dictionary.keys()[i],
self.dock_tab3_1.techCombo.currentText(), temp_check))
temp_layout.addWidget(temp_check)
在这里,我有一个具有复选框列表的 ScrollArea。问题是,当在 GUI 上切换复选框时,会为 scrollArea 中的所有复选框调用 updateDataDictionary 方法,而不仅仅是切换的复选框。
因此,理想情况下,当相应的复选框被切换时,只有一个条目必须从 1 变为 0。但是我字典中的所有条目都被修改为 0。
我该如何解决这个问题?