2015-02-04 20 views
3

QSplitter 여기에서 오른쪽 창은 QCustomPlot이고 왼쪽 창 (트리보기)을 클릭하면 그래프가 표시됩니다. 문제는 그래프가 표시되지 않거나 스플리터 크기를 조정할 때까지 업데이트되지 않는다는 것입니다. (이 예에서처럼) 내가 생성자에서이 함수를 호출 할 때QCustomPlot/위젯에 그래프/업데이트가 표시되지 않습니다.

void MyDialog::setupPlot(QCustomPlot *customPlot) 
{ 
    QString demoName = "Quadratic Demo"; 
    // generate some data: 
    QVector<double> x(101), y(101); // initialize with entries 0..100 
    for (int i=0; i<101; ++i) 
    { 
     x[i] = i/50.0 - 1; // x goes from -1 to 1 
     y[i] = x[i]*x[i]; // let's plot a quadratic function 
    } 
    // create graph and assign data to it: 
    customPlot->addGraph(); 
    customPlot->graph(0)->setData(x, y); 
    // give the axes some labels: 
    customPlot->xAxis->setLabel("x"); 
    customPlot->yAxis->setLabel("y"); 
    // set axes ranges, so we see all data: 
    customPlot->xAxis->setRange(-1, 1); 
    customPlot->yAxis->setRange(0, 1); 
} 

과정의 플롯이 표시되지만 버튼에서 호출이 클릭되지 않을 경우 : 내가 Qt는 예제 코드를 사용하고 있습니다.

이 함수를 호출 할 때 그래프가 플롯되어 있는지 확인하려면 어떻게해야합니까?

답변

3

당신은 음모를 업데이트 replot() 기능을 사용해야합니다

customPlot->replot(); 

그것은 내부 버퍼에 완벽한 replot됩니다. 그래프의 축 범위 나 데이터 포인트를 변경할 때이 메서드를 호출해야합니다. 이렇게하면 변경 내용이 표시됩니다.

+0

감사합니다. 그 덕분에 update(), repaint()가 작동하지 않는 이유는 무엇입니까? – zar

+4

업데이트 또는 다시 그리기는 QCustomPlot의 내부 구조, 버퍼 등을 사용하지 않습니다. 모든 것을 준비시키기 위해서'replot'을 호출해야합니다. 내부적으로'update'를 호출합니다. – Nejat