I've got a QtTreeView
and a class Foo
derived from QAbstractItemModel
attached to it.
In Foo::data
I set the Qt::BackgroundRole
for each element of the tree according to the status of some internal data.
When I receive a signal to update my internal data I would like to update the background of each item accordingly, but I can't seem to reliably make Qt call my Foo::data
method.
I've tried calling update()
and repaint()
(on the view), to no avail. Calling reset()
works but I lose all the state of the tree (e.g. expanded elements etc.). Calling setData()
on each element also works but the code gets a bit awkward as I have to explicitly rebuild the tree of data displayed which is not nice.
How can I force Qt to call data()
on my model?
You need to inform the view class your model has changed, by emitting the dataChanged signal.