簡體   English   中英

QCustomPlot / Widget不顯示圖形/更新

[英]QCustomPlot/Widget doesn't show graph/update

我正在使用QSplitter ,右側窗格是QCustomPlot ,當我在左側窗格(樹視圖)中單擊時,它會顯示一個圖形。 問題是圖表在我調整分割器大小之前沒有顯示或更新。 我正在使用Qt示例代碼:

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

當我在構造函數中調用此函數時(如示例中所示),當然會顯示繪圖,但如果在單擊按鈕時調用此函數則不會顯示。

當我調用此函數時,我需要做些什么才能確保繪制圖形?

你應該使用replot()函數來更新圖:

customPlot->replot();

它會導致完整的重新插入內部緩沖區。 當您對圖形的軸范圍或數據點進行更改時,必須調用此方法。 這使得更改可見。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM