[Qt-interest] QListView & custom QAbstractListModel - How do I notify list view of changes from inside my model?

Josiah Bryan jbryan at productiveconcepts.com
Wed Sep 23 22:41:33 CEST 2009


Hey all -

I've got a custom QAbstractListModel I'm using with a QListView. The 
model itself monitors the internal data (in this case, a QGraphicsItem) 
for changes (say, position or geometry), and when the internal data 
changes, I want it to notify the list view of the change so it can 
re-query the model for the new data (in this case, a custom pixmap that 
gets redrawn.)

Currently, I've solved that in the class that creates the model and list 
view by connecting to a custom signal on my list model ("modelChanged") 
that the model emits when the internal data changes. Then my window 
class calls "reset()" on the QListView which appears to do the job of 
re-querying the model.

However, the "reset()" call also looses the currently selected index 
(e.g. the current item the user has selected is no longer highlighted), 
which leads me to believe that this is not the correct way to notify the 
model of minor changes.

What is the "official" way for a custom model to notify the view about 
changes? Say, add items, remove items, or an item changed?

Thanks!
-josiah


--
Josiah Bryan
Productive Concepts, Inc.
jbryan at pciint.com
(765) 964-6009, ext. 224




More information about the Qt-interest-old mailing list