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);
天道酬勤 循序渐进 技压群雄
浙公网安备 33010602011771号