Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

[Solved] How to update an element of DataModel from QML and request an update of the ListView?

$
0
0
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);

Viewing all articles
Browse latest Browse all 4972

Trending Articles