def __init__(self, data):
        """
        # -- Type -- Color
        |-- item_type(Fruit)
        |   |-- name(Apple) -- color(Red)
        |   |-- name(Banana) -- color(Yellow)
        |-- item_type(
        :param data:
        """
        QStandardItemModel.__init__(self, 0, 2)
        self.setHeaderData(0, Qt.Horizontal, "Type")
        self.setHeaderData(1, Qt.Horizontal, "Color")

        for i, v in enumerate(data):
            item_type = data[i]['type']

            row_items = list()
            column_items = list()

            for j, x in enumerate(data[i]['objects']):
                name, color = data[i]['objects'][j]
                item = QStandardItem(item_type)
                child = QStandardItem(name)
                row_items.append(child)
                column = QStandardItem(color)
                column_items.append(column)

            item.appendRows(row_items)
            item.appendColumn(column_items)
            self.setItem(i, 0, item)
Пример #2
0
    def __init__(self, data):
        """
        # -- Type -- Color
        |-- item_type(Fruit)
        |   |-- name(Apple) -- color(Red)
        |   |-- name(Banana) -- color(Yellow)
        |-- item_type(
        :param data:
        """
        QStandardItemModel.__init__(self, 0, 2)

        # 하나의 아이템만 받도록 되어 있음
        self.setHeaderData(0, Qt.Horizontal, "Type")
        self.setHeaderData(1, Qt.Horizontal, "Color")

        row_items = list()
        column_items = list()
        item_type = data[0]['type']
        name, color = data[0]['objects'][0]

        item = QStandardItem(item_type)

        child = QStandardItem(name)
        row_items.append(child)
        column = QStandardItem(color)
        column_items.append(column)

        name, color = data[0]['objects'][1]
        child = QStandardItem(name)
        row_items.append(child)
        column = QStandardItem(color)
        column_items.append(column)

        item.appendRows(row_items)
        item.appendColumn(column_items)
        self.setItem(0, 0, item)