View Full Version : How to update scene after removing items

20th September 2007, 07:45
I want to update scene/view after deleting all items from scene.
Even if deleting all items from scene and calling scene's update, graphics view's repaint, screen is showing all items. I have minimize and then maximize the window to refresh it.
Please tell me how to do ?
Tell me what is wrong in following code ??
my code is

//delete all items
QList<QGraphicsItem *> l = scene->items();
for(QList<QGraphicsItem *>::iterator it = l.begin(); it != l.end(); ++it)
QGraphicsItem *item = *it;
delete item;

//Delete scene
delete scene;

//Update view

20th September 2007, 07:48
Deleting the scene also deletes the items.
You're not getting an update because the view doesn't know what to update, because you delete its scene.
Is that necessary? It is empty anyway. At least set a new one.

20th September 2007, 08:02
Ya i want to delete scene from view too. How to remove/delete scene from view ???
how to refresh screen in this case ??

20th September 2007, 09:56
Deleting a scene automatically removes it from all associated views. There must be something weird going on. Perhaps the event loop is blocked or something? Could you paste more code, where and when exactly do you do this removal and deletion?

20th September 2007, 10:56
I have background picture(.png file) drawn on scene's drawBackground(...) function, and after that I addded rectangles in it. But when I doing above code to clear background picture as well items drawn, the screen is not refreshing. I have to do minimize/maximize to refresh screen.