I want to color a cell in a QTableView
.
So I'm trying to change the itemData
of the corresponding item in the associated QTableModel
.
To do so, I use the setItemData
method of the QAbstractTableModel
class.
In the documentation :
QAbstractItemModel::setItemData(const QModelIndex & index, const QMap < int, QVariant > & roles)
This is my piece of code :
color = QtGui.QColor(Qt.red)
self.model.setItemData(self.model.index(3,3),color,Qt.BackgroundRole)
I thought this would color the third cell of the model (horizontally and vertically) in red.
But the application answers :
TypeError: QAbstractItemModel.setItemData(QModelIndex, dict-of-int-QVariant): argument 2 has unexpected type 'QColor'
If I try to transform the Qcolor
type in a Qvariant
:
color = Qt.QVariant(QtGui.QColor(Qt.red))
self.model.setItemData(self.model.index(3,3),color,Qt.BackgroundRole)
Answer :
TypeError: PyQt4.QtCore.QVariant represents a mapped type and cannot be instantiated
Which I really can't understand.
So there is my question : which type of data must I put in the second parameter of a setItemData
method?
Thanks for advance