PDA

View Full Version : Single Item update in QGraphicsView



oberlus
27th August 2010, 10:17
Hi,

Is it possible to have a QGraphicsView update a single graphical item?

I have an application which uses the following hierarchy (roughly):

QAbstractItemModel <- ConcreteModel

QGraphicsView <- ConcreteGraphicsView

QObject, QGraphicsPolygonItem, QGraphicsLayoutItem <- ConcreteGraphicsItem

ConcreteGraphicsView contains a QGraphicsScene object and also has access to the QAbstractItemModel.

The application works fine in the sense I can get all of the graphics items laid out and displayed.

Now I would like to change one of the item data and have the view automatically update just the item I changed (not the whole view). I can have the whole view change by explicitly clearing the scene and rebuilding it by iterating through the model within the view object, but apart from being an overkill it resets the layout of the items which may have been manually re-arranged through the view.

I've read (http://stackoverflow.com/questions/1004701/model-view-controler-in-qt)about delegates in the context of the QAbstractItemView and the fact QAbstractItemView implements the observer pattern, but I can't figure out how I can apply these concepts in my application given I'm using a QGraphicsView.

As an experiment I modified the model class to fire a QTimer connected to a slot which emitted a layoutChanged() signal, but I never see the view call the model data() method to retrieve anything.

Thanks in advance for any help.