I populated a QTreeView with a database, and I would like to access the data stored in each row in order to sum the values. I don't find any command or method that gives an easy access to those data. I am looking for something like this :
res = 0
for row in self.view.model().rows() :
res += row[0]
return res
Any ideas ? EDIT I found the answer to my question so I'll post it right below :
index : QModelIndex = self.view.selectionModel().currentIndex()
model: QAbstractItemModel = self.model
parent: QModelIndex = index.parent()
child : QModelIndex = model.index(index.row()+1,2,parent)
res = 0
for i in range(self.model.rowCount()) :
child = model.index(row_count,0,parent)
self.setCurrentIndex(child)
res += self.view.currentIndex().siblingAtColumn(0).data()
print(res)