即使只有一个在pyQT中切换,QCheckbox信号也会发出所有chechbox?

时间:2017-07-16 17:36:15

标签: python pyqt pyqt4 qcheckbox

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。

如何解决此问题?

0 个答案:

没有答案