Thanks for the helpful manual. But there is a little error.
def data(self, index, role):
# existing if role == **Qt.ItemDataRole.DisplayRole:** block hidden
# hidden for clarity.
if role == **Qt.BackgroundRole** and index.column() == 2:
# See below for the data structure.
return QtGui.QColor('blue')
should be Qt.ItemDataRole.BackgroundRole
Further:
If I use the following snipped, no Icon will be shown. I've used your data example:
def data(self, index, role):
if role == Qt.ItemDataRole.DisplayRole:
value = self._data[index.row ()][index.column ()]
if isinstance (value, datetime):
return value.strftime ('%Y-%m-%d')
return value
if role == Qt.ItemDataRole.DecorationRole:
value = self._data[index.row ()][index.column ()]
if isinstance (value, datetime):
return QtGui.QIcon ('calendar.png')
if role == Qt.ItemDataRole.DecorationRole:
value = self._data[index.row ()][index.column ()]
if isinstance (value, bool):
if value:
return QtGui.QIcon ('tick.png')
return QtGui.QIcon ('cross.png')
BTW:
Could you extend this example for Qt.ItemDataRole.CheckStateRole. I can't get a checkbox with returning the changed value and reflecting the state in the TableView
Thanks for the helpful manual. But there is a little error.
should be Qt.ItemDataRole.BackgroundRole
Further:
If I use the following snipped, no Icon will be shown. I've used your data example:
BTW: Could you extend this example for Qt.ItemDataRole.CheckStateRole. I can't get a checkbox with returning the changed value and reflecting the state in the TableView