c++ - QCustomPlot/Widget 不显示图形/更新

标签 c++ qt qcustomplot

我正在使用 QSplitter,其中右 Pane 是 QCustomPlot,当我单击左 Pane ( TreeView )时它会显示一个图表。问题是在我调整拆分器的大小之前,图表不会显示或更新。我正在使用 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();

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

关于c++ - QCustomPlot/Widget 不显示图形/更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28328941/

相关文章:

c++ - operator< 用于列表排序

c++ - QPainter彩色文本(语法着色)

c++ - QcustomPlot 不想绘制图形

c++ - QXmlStreamReader获取标签值

c++ - QML 中的类型化数组? QByteArray 到 JS Uint8Array 来回互操作

c++ - 如何在线程中更新 QCustomPlot 数据?

c++ - QCustomPlot QCPItemEllipse 位置

c++ - C++ MFC 程序是完全原生的吗?

C++ 未执行的代码改变函数行为?

C++ Lambda、捕获、智能 Ptr 和堆栈 : Why Does this Work?