I try to set the color of a selected item in a QTreeView using the QAbstractItemModel in PySide2.
So what i am trying right now is creating a context menu and then having a method to colorize that selected item.
def colorize_item(self):
index = self.treeview.selectionModel().currentIndex()
self.model.setData(index, QtGui.QBrush(QtCore.Qt.red), QtCore.Qt.ForegroundRole)
Sadly it is not working at all. I successfully used the data() method in the QAbstactItemModel to change the color of all items text but i need to colorize specific items in the TreeView. I also used Google to find a solution but nothing worked for me :(
EDIT: i also tried to not override the setData() method just to check if my override just messed something up.
EDIT: Maybe a better question would be what to implement in setData to make it work