用Qt c++绘制光滑曲线

Drawing smooth curve with Qt C++

本文关键字:曲线 绘制 Qt c++      更新时间:2023-10-16

我有一组点要绘制,它们的坐标存储在

QVector<double> x(200), y(200);

我想把它们和一些光滑的曲线连接起来,比如样条。或者在结点之间设置更大的点阵列也足够了。我的尝试是

    customPlot->addGraph();
    customPlot->graph(0)->setData(x, y);
    customPlot->graph(0)->setPen(QPen(Qt::blue));
    customPlot->xAxis->setLabel("Index");
    customPlot->yAxis->setLabel("Amplitude");
    customPlot->xAxis->setRange(0, 200);
    customPlot->yAxis->setRange(-3, 3);

我尝试了QPainterPath类,但它不起作用。请帮帮我。

UPD:我现在正在看QEasingCurve类,这些函数可能有帮助,但作者没有提供示例,我不知道如何使用它们

从代码中我可以看出您正在使用QtCharts

有一个QSplineSeries,你可以使用它做你想要的。