3

我正在使用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);
}

当我在构造函数中调用此函数时(就像在示例中一样),当然会显示该图,但如果在单击按钮中调用此函数则不会。

我需要做什么来确保在调用此函数时绘制图表?

4

1 回答 1

3

您应该使用replot()函数来更新绘图:

customPlot->replot();

它会导致完全重新绘制到内部缓冲区中。当您对图表的轴范围或数据点进行更改时,必须调用此方法。这使更改可见。

于 2015-02-04T18:46:51.100 回答