2012-09-03 1 views
1

저는 여기 새로 왔으며이 문제를 해결할 수 없습니다. QGraphicScene (처음에는 직교 좌표계를 초기화합니다)에는 AddLine \ ecc.Everything works.But 메서드를 사용하여 점선을 그립니다.하지만 장면에 그려진 모든 "객체"를 삭제하고 다시로드하는 메서드가 필요합니다. 데카르트 비행기 야. 어떤 제안? ,QGraphicsScene clear display

class draw: public QWidget 
{ 
    Q_OBJECT 

private: 

    QGraphicsScene scene; 
    int x1; 
    int y1; 
    int x2; 
    int y2; 

public: 
    disegna (QWidget *parent = 0); 
    void setdot(QString,QString); 
    void setsegment(QString,QString,QString,QString); 
    ~disegna(){} 
    }; 

draw::draw(QWidget *parent) : QWidget(parent) { 
    scene.setBackgroundBrush(Qt::white); 
    scene.addRect(QRectF(0,0, 600, 200)); 
    scene.addLine(0, 100 ,600, 100); 
    scene.addLine(300, 0 ,300, 200); 
    scene.addEllipse(297.5,97.5,5,5,QPen(), QBrush(Qt::red)); 

    int i=0; 
    for (int a=0;a<120;a++) { 
     scene.addLine(i+5, 98 ,i+5, 102); 
     i=i+5; 
    } 

    int j=0; 
    for (int a=0;a<40;a++) { 
     scene.addLine(298,j+5,302,j+5); 
     j=j+5; 
    } 

    QGraphicsView * view = new QGraphicsView(&scene,this); 
    view->show(); 
} 

void draw::setdot(QString x1,QString y1){ 
    scene.addEllipse(x1.toInt()+298, 98-y1.toInt(),4,4,QPen(), QBrush(Qt::blue)); 
} 

void draw::setsegment(QString x1,QString y1,QString x2,QString y2) { 
    scene.addLine(x1.toInt()+300, 100-y1.toInt(),x2.toInt()+300, 100-y2.toInt(),QPen()); 
    scene.addEllipse(x1.toInt()+298, 100-y1.toInt(),4,4,QPen(), QBrush(Qt::blue)); 
    scene.addEllipse(x2.toInt()+298, 100-y2.toInt(),4,4,QPen(), QBrush(Qt::blue)); 
} 

답변

3

장면을 청소 당신은 clear 방법을 시도했다 : 여기

내 수업을 찾을 수 있습니까?

지우기 및 다시 그리기를 원할 경우 생성자에서 메서드로 드로잉 코드를 이동하는 것이 좋습니다. 그런 다음 그리기 방법을 명확하게 호출 할 수 있습니다.

희망 하시겠습니까?

+0

감사합니다. Jokahero, 고맙습니다. – Nicola