1

After updating the model data of my derived class of a QAbstractItemModel, I do not want the listeners (assume a QTreeView) to completely update all of the tree representation, but only the data in an individual column of most of the rows.

Example: I want to only update the second column of my items, so I thought I had to
emit dataChanged(createIndex(0,1,&root), createIndex(rowCount(),1,&root);

However, this still updates the complete tree for some reason - is that expected behaviour? Does it have to do with the underlying model organisation (which works very similar to Qt's own simple tree example)? Or does it have yet other reasons I did not consider?

Sty
  • 760
  • 1
  • 9
  • 30
  • I would do it in this way: `emit dataChanged(QModelIndex(0, 1), QModelIndex(rowCount() - 1, 1));` – vahancho Nov 03 '17 at 15:20
  • Oops, yeah, rather obvious mistake, I should say. But that way it only changes the data in one single item now, not in all rows. As I understand, both the ul and the lr model indices need to have the same parent, though, and trying to reference a deeper node for the internal pointer just results in everything updating again... – Sty Nov 03 '17 at 15:29
  • The mentioned call was for top level nodes, indeed. If you need to update another branch, you need to know the model index of its parent. Please note from Qt docs: "If the items do not have the same parent, the behavior is undefined." – vahancho Nov 03 '17 at 15:36
  • Yes, I read that part, which is why I was sceptical about its chances before trying it out already, but I just tried it out anyways. In any case, do I understand your first statement correctly that in order to update one column in the entire tree, I'd have to emit `dataChanged` signals for every (parent) node in the tree? – Sty Nov 03 '17 at 15:39
  • Yes, I guess so. You have to update each branch (children of the same parent) separately. Probably recursively. However take into account that not all nodes are visible at a time. You don't need to update them all. – vahancho Nov 03 '17 at 15:44
  • Hm, that is not what I hoped to hear, but I'll accept that as an answer. Thank you. – Sty Nov 03 '17 at 15:46

0 Answers0