1

Tried:

    def setTreeValues(self, data: [numpy.array]) -> None:
        """
        ARGS:
                 ID    signals         sum_errors max_error number_errors status
                (int)  (str)          (float)    (float)    (int)       (str)
         data = [1,    'Car.distance', NAN,       NAN,       NAN,       'file missing'],
                [2,    'Car.v',        500.32,    100.47,    4,         ''],
                                          .
                                          .
                [100,  'Car.ax,        50.86,      10.3,     10,        '']
        """

        QTreeWidgetItemList = []  # list of QTreeWidgetItem to add
        (row_length, column_length) = data.shape
        for row_index in range(row_length):
            treeWidgetItem = QtWidgets.QTreeWidgetItem(row_index)
            for column_index in range(column_length):
                treeWidgetItem.setData(column_index, 0, data[row_index][column_index])
            QTreeWidgetItemList.append(treeWidgetItem)
        self.treeWidget.addTopLevelItems(QTreeWidgetItemList)  # add everything to the tree

The code works but is there an easier way to link my view to my model? i.e something that looks like this: self.treeWidget.data = MDFsData

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
  • No, there is not. There are dozens of different ways to structure and visualize data, so there cannot be a common interface to do that. Besides, it doesn't seem like you're actually using a tree structure, so you could just use a QTableWidget. Also note that you should not use the row index (or any number) in the QTreeWidgetItem constructor, because that signature has a different purpose, and since you're overwriting the column data, that `row_index` argument is actually useless anyway. – musicamante Jun 02 '23 at 16:50

0 Answers0