Leo Leo - 8 months ago 64
C++ Question

Delete all lines from QGraphicsScene

I am having a very hard time to find a way to delete all lines added to a

. Let's say we have this 6 lines. How do I delete them later, after some processing? or in other words, how do I get a white and empty scene again?

QPen pen(Qt::blue, 1);
QLineF line(10, 20, 100,100);
line.setLine(100, 100, 100,100);
scene.addLine(line, pen);

By the way,
does not seem to work.

Leo Leo

I solved it storing all lines in a list and when I want to clear the scene I delete all pointers inside the list:

QList<QGraphicsItem *> list;
list << scene.addLine(x1, y1, x2, y2, pen); // store line pointer
void mainWindow::emptyList(void){ // delete all pointers in list (clear)
    int iNum = list.count();
    for (int i=0; i<iNum; i++)
        delete list.takeAt(0);