thanks for the hints now it works. Here is my solution. In my setter method I create an QModelIndex. With this I call my overwritten setData method. In the setData method I update the data and send the dataChanged() signal. The setter method is called from QML with the index of the ListView element I want to changed.
C++:
bool MyColorModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
MyColor* myColor = _pMyColorList->at(index.row());
if (role == IdRole)
myColor->setId(value.toString());
else if (role == ColorRole)
myColor->setColor(value.toString());
emit dataChanged(index, index);
return TRUE;
}
void MyColorModel::setColor(int index, QVariant color)
{
QModelIndex modelIndex = this->index(index);
setData(modelIndex, color, ColorRole);
return;
}
QML:
colorModel.setColor(selectedIndex, colorpicker.colorValue);
↧