QAbstractItemModel & QTreeView notifications...
-
Hey
I'm trying to wrap my head around item model system.
Say I have
treeViewA
treeViewB
boths use
modelAto display data. Say in treeViewA I 2x click on an item and rename it, the name changes in treeViewA but also in treeViewB. Which means that setData, was sent to model, which forwarded it to item, and then the models must have notified the treeViews that data has changed and they need to redraw. I take there are either full redraw flags or just changed item flags. What I want to know is, what function does model call on treeView that tells it to redraw, how can I subclass it/replace it? Say my treeViews is linked to a widget displaying data of the selected item, if selection change, then every treeView should notify their own data widgets to update as well. Another example could be that if I rename a item, I would want that rename to trigger other events too for each treeViews.
Can any1 hint me in to right direction?
TIA
-
Hi,
dataChanged is the signal you are looking for.
-
@Dariusz said in QAbastractItemModel & QTreeView notifications...:
Wait thats dataChanged on model one, what about treeView one? I need tree to react to data/specific data change not model.
What you are asking here is not really clear.
Your views are going to get notified that something has changed and are going to re-read the model's data to update the concerned items.
-
What I want to know is, what function does model call on treeView that tells it to redraw
None. Model doesn't know anything about the existance of a view (or views). The relationship is the inverse - it's the view that connects to model's signals when you call
setModel()
on it. As for what signals are emmited by the model - see the documentation of QAbstractItemModel. There are pairs of before/after signals for different operations, e.g.rowsAboutToBoInserted()
/rowsInserted()
. There's also the mentioneddataChanged()
for when a range of items changes one of its roles values.Say my treeViews is linked to a widget displaying data of the selected item, if selection change, then every treeView should notify their own data widgets to update as well.
Selection is not a function of the model. This is handled by a selection model that is set on the view, so each view has its own. You can connect to its selectionChanged() signal.
Another example could be that if I rename a item, I would want that rename to trigger other events too for each treeViews.
This you can handle by connecting to the
dataChanged()
signal of the model as mentioned aboveWait thats dataChanged on model one, what about treeView one? I need tree to react to data/specific data change not model.
The data changes in the model so you connect to the model's signals not the view. The views provided by Qt already connect to all the signals of the model. If you want to do extra things in the view you can subclass and connect again to the signals of your choice. You can make the connections in the override of
setModel()
of your subclass.