QCustomPlot / Widget不显示图形/更新

时间:2022-06-30 18:46:16

I am using QSplitter where the right pane is QCustomPlot which shows a graph when I click in the left pane (a tree view). The problem is the graph doesn't show up or updates until I resize the splitter. I am using Qt example code:

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

The plot of course shows up when I call this function in the constructor (like it is in the example) but not if call this in button clicked.

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

What do I need to do to make sure the graph is plotted when I call this function?

当我调用此函数时,我需要做什么来确保绘制图形?

1 个解决方案

#1


3  

You should use replot() function to update the plot :

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

customPlot->replot();

It causes a complete replot into the internal buffer. This method must be called when you make changes on the axis ranges or data points of graphs. This makes the changes visible.

它会导致完整的重新插入内部缓冲区。当您对图形的轴范围或数据点进行更改时,必须调用此方法。这使得更改可见。

#1


3  

You should use replot() function to update the plot :

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

customPlot->replot();

It causes a complete replot into the internal buffer. This method must be called when you make changes on the axis ranges or data points of graphs. This makes the changes visible.

它会导致完整的重新插入内部缓冲区。当您对图形的轴范围或数据点进行更改时,必须调用此方法。这使得更改可见。