[英]Delete all lines from QGraphicsScene
I am having a very hard time to find a way to delete all lines added to a QGraphicsScene
. 我很难找到一种方法来删除添加到
QGraphicsScene
所有行。 Let's say we have this 6 lines. 假设我们有这6行。 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);
scene.addLine(line,pen);
line.setLine(100, 100, 100,100);
pen.setWidth(3);
scene.addLine(line, pen);
By the way, scene.clear()
does not seem to work. 顺便说一句,
scene.clear()
似乎不起作用。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.