PDA

View Full Version : Updating QGraphicsView



has2k1
8th April 2007, 12:23
I am writing my first qt program which heavily relies on QGraphicsScene/View. The first items added to the scene(s) while the program starts up show up as expected, while the items I add as it runs are not shown in the view. However, they show up if I rotate the view 360 degrees.

Is there a way I can force the view to update without having to do an expensive rotation. I think I have tried all the functions in scene/view that I think should force an update and non do.

linux, qt 4.2.2


QGraphicsPixmapItem *particle = new QGraphicsPixmapItem(particlepng);
particle->setPos(xpos[i],ypos[i]);
//particle->update(0,0,10,10);
holeScene[holeNum]->addItem(particle);
//holeView[holeNum]->rotate(360);

Hope I've given enough info, Thanks

Gopala Krishna
8th April 2007, 18:49
I am writing my first qt program which heavily relies on QGraphicsScene/View. The first items added to the scene(s) while the program starts up show up as expected, while the items I add as it runs are not shown in the view. However, they show up if I rotate the view 360 degrees.

Is there a way I can force the view to update without having to do an expensive rotation. I think I have tried all the functions in scene/view that I think should force an update and non do.

linux, qt 4.2.2


QGraphicsPixmapItem *particle = new QGraphicsPixmapItem(particlepng);
particle->setPos(xpos[i],ypos[i]);
//particle->update(0,0,10,10);
holeScene[holeNum]->addItem(particle);
//holeView[holeNum]->rotate(360);

Hope I've given enough info, Thanks

Firstly answer to the point:
You can force update by updating the whole scene or view like
holeScene ->update() and holeView ->update()

But the code confuses me a bit. Looks like you are using number of scenes for your program. Not a problem, but are you sure you need more scenes. Or do the scenes correspond to multiple tabs/windows ??

Also the docs clearly indicate the scene and hence the view is updated whenever an item is added to scene. Just make sure you get the scene,view and item relations right. :)

has2k1
8th April 2007, 22:02
Thanks Gopala. That works really fast. It just did not occur to me that I would have to look at inherited functions from QWidget for that functionality. I had tried QgraphicsView->updateScene to no luck.