TreeView and problem with dataChanged
-
Hello,
I implemented a treeview in QML and i have a problem with dataChanged. It does not update the tree at all. I used "layoutChanged" and it works then, but that's kind of overkill as it reads again all data.I can see that that after i call dataChanged, the "parent" method is called for the item i want to update. No other methods are called.
I have a Root structure which contains all the items. Root iself is not shown in the tree. As the item i want to update is in Root, the parent method returns empty QModelIndex. I tried to return Root with index 0 but it did not help.
The problem is also visible even if Root is not the parent but another item.
QModelIndex TreeViewModel::parent(const QModelIndex &index) const { qDebug() << "parent called"; QModelIndex modelIndex; if (index.isValid()) { FileData* item = static_cast<FileData*>(index.internalPointer()); qDebug() << "parent called for: " << item->filename; if (item->parent && item->parent != rootItem) { qDebug() << "parent: " << item->parent->filename << " - " <<item->parent->index; modelIndex = createIndex(item->parent->index, 0, item->parent); } } return modelIndex; } void TreeViewModel::updateData(FileData *item) { //emit layoutAboutToBeChanged(); qDebug() << "updateData called"; QModelIndex index = createIndex(item->index, 0, item); emit dataChanged(index, index, QList<int>({DownloadProgressRole, IsDownloadedRole})); //emit layoutChanged(); }In the QML file, inside TreeView i put
rootIndex: manager.modelIndexwhich returns the Root item.
Any idea what could be wrong?
-
C Chilli0 has marked this topic as solved on