PDA

View Full Version : How to clear QGraphicsScene



penny
16th February 2011, 07:17
I'm using QGraphicsScene to plot data. On pressing a button on the toolbar, i want contents of the QGraphicsScene to get cleared and do a fresh plot.
However, writing scene1->clear() doesn't seem to work..
Am i using it wrongly, or is there another way?

Zed
16th February 2011, 09:57
clear() should work (to clear your graphicsitem, previously added to the scene).
Anyway, the data that you plot is an object? and if so, what kind?

You should post some snippets.

vcp
16th February 2011, 12:13
Hi,

You can use this technique:

QList<QGraphicsItem*> item = graphicView->items();
qDeleteAll(item);

This will delete all items of object

Works fine to me.