QCustonPlot添加曲线平滑功能

qcustomplot.h

class QCP_LIB_DECL QCPGraph : public QCPAbstractPlottable1D<QCPGraphData>
{
public: 
    ...
    void setSmooth(bool smooth);             // 新增内容
    
protected:
    ...
    bool mSmooth;                            // 新增内容
}

 qcustomplot.cpp

QCPGraph::QCPGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) :
  QCPAbstractPlottable1D<QCPGraphData>(keyAxis, valueAxis)
{
    ...
    mSmooth = false;  // 新增内容
}

 

void QCPGraph::setSmooth(bool smooth)
{
    mSmooth = smooth;
}

 

void QCPGraph::drawLinePlot(QCPPainter *painter, const QVector<QPointF> &lines) const
{
    if (painter->pen().style() != Qt::NoPen && painter->pen().color().alpha() != 0)
    {
        applyDefaultAntialiasingHint(painter);
        if (mSmooth && mLineStyle == lsLine) painter->drawPath(SmoothCurveGenerator::generateSmoothCurve(lines));
        else drawPolyline(painter, lines);
    }
}

 启用平滑曲线

ui->Plot->graph(0)->setSmooth(true);

 

posted @ 2024-11-19 16:50  wuyuan2011woaini  阅读(46)  评论(0编辑  收藏  举报