从 QTreeWidget 的子 Qtable 获取内容

Get contents from Qtable which is a child of QTreeWidget

我创建了一个包含 table 个子项的树形小部件。我想访问 QtableWidget 的内容,但找不到如何操作?

树形小部件如下所示:

我生成的树形小部件如下:

        software = QTreeWidgetItem(['Software'])
        hardware = QTreeWidgetItem(['Hardware'])
        beide = QTreeWidgetItem(['Beide'])
        andere = QTreeWidgetItem(['Andere'])          
        i = 0
        for key, value in sorted(data.items()):
                if value['Subtype'] == 'Software':
                    sub = software
                if value['Subtype'] == 'Hardware':
                    sub = hardware
                if value['Subtype'] == 'Beide':
                    sub = beide
                if value['Subtype'] == 'Andere':
                    sub = andere

                l1 = QTreeWidgetItem(sub)

                if value['Privacy'] == 'Voorzichtig':
                    l1.setBackgroundColor(0, QColor('orange'))
                if value['Privacy'] == 'Vertrouwelijk':
                    l1.setBackgroundColor(0, QColor('red'))
                    l1.setTextColor(0, QColor('white'))

                l1.setText(0, value['sDesc'])

                self.treeMainDisplay.addTopLevelItem(l1)

                l1_child = QTreeWidgetItem(l1)

                self.item_table = QTableWidget()
                self.item_table.verticalHeader().setVisible(False)
                self.item_table.horizontalHeader().setVisible(False)
                self.item_table.setColumnCount(5)
                self.item_table.setRowCount(5)
                c1_item = QTableWidgetItem("%s" % value['sDesc'].encode('utf-8'))
                self.item_table.setItem(0, 0, c1_item)
                c2_item = QTableWidgetItem("%s" % value['Type'].encode('utf-8'))
                self.item_table.setItem(1,0, c2_item)

                qt_child = self.treeMainDisplay.setItemWidget(l1_child, 0,  self.item_table)  

        self.treeMainDisplay.addTopLevelItem(software)
        self.treeMainDisplay.addTopLevelItem(hardware)
        self.treeMainDisplay.addTopLevelItem(beide)
        self.treeMainDisplay.addTopLevelItem(andere)

我正在迭代 treewidgetitems,但不知道如何访问 table 内容:

def testItems(self):
    iterator = QTreeWidgetItemIterator(self.treeMainDisplay)
    while iterator.value():
        item = iterator.value()
        if not item.text(0):
            #Get Table Object?
            # item.item(0,0).text()
        else:
            print item.text(0)
        iterator += 1

我似乎无法访问 QTableWidget 对象,我只能访问 QTreeWidgetItem 对象。

非常感谢所有反馈!

项目小部件必须使用 itemWidget 方法通过树小部件访问:

def testItems(self):
    iterator = QTreeWidgetItemIterator(self.treeMainDisplay)
    while iterator.value():
        item = iterator.value()
        if not item.text(0):
            # Get Table Object
            table = self.treeMainDisplay.itemWidget(item, 0)
        else:
            print item.text(0)
        iterator += 1