I was trying to code a small ToDo app and stumbled upon lack of understanding of how Model handles Roles, I mean, how does it differentiate one Role from another one? Does it, like, check out all of them at the same time?
I would be glad to quench my curiosity
class TodoModel(QtCore.QAbstractListModel):
""" Model for handling data"""
def __init__(self, todos=None, *args, **kwargs):
super(TodoModel, self).__init__(*args, **kwargs)
self.todos = todos or []
def data(self, index, role):
if role == Qt.DisplayRole: #That Line
status, text = self.todos[index.row()]
return text
if role == Qt.DecorationRole: #And This One
status, text = self.todos[index.row()]
if status:
return tick
def rowCount(self, index):
return len(self.todos)
