Changing the value of DecorationRole Value in QTreeView on the fly
-
Hi
I have a QtreeView and I am displaying colored rectangle images in the first column for each row in QTreeView . The requirement in when the user clicks on the colored rectangle a QColorDialog comes up and then when the picks the color and sets ok then the colored rectangle should change .Can someone guide me on thisThe code is something like this
QVariant myModel::data(const QModelIndex& index, int role) const
{
switch (role) {
case Qt::DecorationRole:
if (index.column() == 1) {
QPixmap cellPixmap(QSize(10,10));
QColor sc = GQUtil::getStandardColor(index.row());cellPixmap.fill(sc); QIcon icon(cellPixmap); return icon; }
}
-
Hi,
You probably have to reimplement setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) and define the color for the Qt::DecorationRole in there. -
If you write a small code , it will be helpful