PyQT QTreeview + QPushButton/QCombobox 信号

PyQT QTreeview + QPushButton/QCombobox signals

我正在尝试加载一系列 dic 文件,然后从 dics 中加载数组到我的 QTreeView,然后能够编辑这些 dics。我在连接信号时遇到问题,因为它将所有按钮连接到 1 个数据 - 最后创建的一个。如果我从 1 个字典加载 20 个数组,我应该能够单击每个数组并打印其名称。现在它只打印最后添加的名称。

代码如下:

def add_data(self):
        for subdir, dirs, files in os.walk(self.dat_folder):
            for file_inx, file_name in enumerate(files):
                ''' loading file '''
                ''' creating data'''

                if len(data[1]) >0:
                    #file_inx = file_inx + 1 # not sure if I need this tbd.
                    job = QStandardItem(project_name)
                    self.model.setItem(file_inx,0,job)
                    self.model.setItem(file_inx, 1, QStandardItem(project_time_day+"  "+project_time_time))
                    for inx, layers in enumerate(data[1]):
                        child1 = QStandardItem(layers["Name"])
                        child2 = QStandardItem("Push Button or Combobox or QCheckBox")
                        job.insertRow(inx,[child1, child2])
                        b=QPushButton("TestPrint"+str(inx))
                        b.clicked.connect(lambda: self.printData(child1.text(),layers["Name"]))

                        a = self.model.index(file_inx, 0) #find parent
                        i = a.child(inx,7) # find parented location
                        self.tv_job_list.setIndexWidget(i,b) # replace child2 with QPushButton - b 

    def printData(self,value,name):
        print value,name  

这是 QTreeView 的样子,每个作业可以有数百个 job_names 并且可以有数百个 Job_01 等等......这是一个很大的列表:-) HDD 上的 1 个文件创建 1 个创建子作业的父项。

Parent > JOB_01
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     ... x 1000 Childs...


Parent > JOB_01
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     Child > Job_Name | Job_Submit_Date | QComboBox | QPushButton | QCheckBox
     ... x 1000 Childs...

使用部分:

  b = QPushButton(str(inx))
  b.clicked.connect(partial(self.printData,child1.text()))