[Qt-interest] QListView & custom QAbstractListModel - How do I notify list view of changes from inside my model?
Eric Clark
eclark at ara.com
Wed Sep 23 22:59:48 CEST 2009
You need to call dataChanged() with the top left and bottom right index that has changed. If it is just one item, then top left and bottom right will be the same.
Eric
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Josiah Bryan
> Sent: Wednesday, September 23, 2009 3:42 PM
> To: 'Qt Interest'
> Subject: [Qt-interest] QListView & custom QAbstractListModel - How do I
> notify list view of changes from inside my model?
>
> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list