2015-02-04 40 views
3

我使用的是QSplitter,右窗格是QCustomPlot,在左窗格(樹視圖)中單擊時顯示圖形。問題是圖表不顯示或更新,直到我調整分離器的大小。我使用Qt示例代碼:QCustomPlot/Widget不顯示圖形/更新

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); 
} 

課程的圖顯示了,當我調用此函數的構造函數(像它在本例中),但如果調用此按鈕點擊。

當我調用此函數時,我需要做些什麼來確保繪製圖形?

回答

3

您應該使用replot()功能更新的情節:

customPlot->replot(); 

它使一個完整的重製到內部緩衝區。當您對圖形的軸範圍或數據點進行更改時,必須調用此方法。這使更改可見。

+0

謝謝,工作,你知道爲什麼更新(),repaint()不起作用? – zar

+4

更新或重繪不使用QCustomPlot的內部結構,緩衝區...。你應該調用'replot'來使一切準備就緒。它在內部調用'update'。 – Nejat