我正在使用QPainterPath在qgraphicsscene上绘制一个多边形。但是,在某些时候,当我想要删除路径时,我无法将其删除。有人能告诉我如何删除/删除绘制的路径。 我正在尝试以下代码。从QGraphicsScene删除路径
In header File:
QGraphicsScene *scene;
QGraphicsPixmapItem *m_pixItem;
QPainterPath m_pathTrack;
QPolygon m_qpolygon;
In cpp file
void MyClass::AddPath()
{
//Slot to add path to the scene
QImage l_img("Path");
graphicsView->setScene(&scene);
m_pixtemItem->setPixmap(QPixmap::fromImage(image));
//Code here to Adding points to polygon. The points are coming at regular interval
m_qpolygon.append(Point);
m_pathTrack.addPolygon(m_qpolygon);
scene.addPath(m_pathTrack);
}
// In slot to delete path
void MyClass::DeletePath()
{
//I tried doing this but the path does not erase
m_pathTrack = QPainterPath();
}
谢谢。
如果不再需要,你必须记得删除它。 – thuga
@thuga你是对的。我没有提到它,因为PathItem将被派往现场并且不会被泄漏。但我会编辑这个建议。谢谢:) – jbh
感谢您的答复。我正在尝试这个,但它并没有删除绘制的整个路径。相反,几个初始点被删除。 – Sid411