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();
}
감사합니다.
scene->removeItem(pathItem);
EDIT (thuga 학점) : 그런 다음 장면에서 제거 할 수있을 것입니다 경로
QGraphicsPathItem* pathItem = scene.addPath(m_pathTrack);
를 추가 할 때
더 이상 필요하지 않은 경우에도 삭제해야합니다. – thuga
@thuga 당신 말이 맞아요. 나는 pathItem이 장면에 부모 역할을하여 유출되지 않을 것이라고 언급하지 않았다. 그러나 나는이 충고를 편집 할 것이다. 감사합니다 :) – jbh
답장을 보내 주셔서 감사합니다. 나는 이것을 시도하고 있지만 그려지는 전체 경로를 삭제하지는 않는다. 대신 초기 지점 몇 개가 삭제됩니다. – Sid411