I have a hierarchical datastructure which I wrapped in a QModel (inherited from QAbstractItemModel) and which I show and edit in a QTreeView.
Let's assume that QTreeView shows the following data:
Item1
|----Item2
|----Item3
|-----Item4
|----Item5
Now the following shall happen:
1) I edit Item3 and change it's value to Item3_a.
2) The QModel recognizes the change and changes the items' values of parents and children in the wrapped model to:
Item1_a
|----Item2_a
|----Item3_a
|-----Item4_a
|----Item5_a
3) The QTreeView gets informed by the model about the additional changes (Item1,2,4 and 5). Only the displayed values are changed. The hierarchical structure remains the same.
My questions aims on step 3:
How do I notify the QTreeView about the changed data properly?
This is what I tried:
I know that there is modelReset
, but then the QTreeView gets collapsed. However it should keep its collpase/expanded state.
According to the docs using models setData
method with different parent indices gives undefined behaviour. I tried calling setData recursivly from setData for each parent/child, but this leads to program crash.
I'm using qt5.
dataChanged
signal. – G.M.dataChanged
. I called dataChanged with the wrong arguments by accident. I'm using pyqt and pyqt shadowed the resulting exception, so that it looked like a program crash ... – Hatatister