QT绘制波形图 QCustomPlot

https://www.qcustomplot.com/
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
qcustomplot.h
qcustomplot.cpp

auto customPlot = ui->centralWidget;
// generate some data:
QVector 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);
customPlot->replot();

promote widget to QCustomPlot

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QCustomPlot 是一款功能强大的 Qt库,它支持多种表类型,并且具有丰富的交互功能和自定义能力。 要在 QCustomPlot 中实现实时波形,可以按照以下步骤进行: 1. 创建一个 QCustomPlot 对象,并添加一个 QCPGraph 对象作为波形的曲线。 ```cpp QCustomPlot *customPlot = new QCustomPlot(this); QCPGraph *graph = customPlot->addGraph(); ``` 2. 设置波形的样式,包括线条颜色、宽度、样式等。 ```cpp graph->setPen(QPen(Qt::blue)); graph->setLineStyle(QCPGraph::lsLine); graph->setAntialiased(true); ``` 3. 在每次需要更新波形时,向 QCPGraph 中添加新的数据点,并重新绘制形。 ```cpp double time = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0; // 获取当前时间戳 double value = ...; // 获取需要绘制的数据值 graph->addData(time, value); // 添加新的数据点 customPlot->rescaleAxes(); // 自适应缩放坐标轴 customPlot->replot(); // 重新绘制形 ``` 4. 在实时绘制过程中,为了不影响绘性能,可以设置 QCustomPlot 对象的自动重绘模式为“不自动重绘”。 ```cpp customPlot->setNoAntialiasingOnDrag(true); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); customPlot->setAntialiasedElements(QCP::aeNone); customPlot->setNotAntialiasedElements(QCP::aeAll); customPlot->setAutoAddPlottableToLegend(false); customPlot->setAutoMargin(true); customPlot->setAutoSubTicks(true); customPlot->setAutoTickStep(true); customPlot->setMultiSelectModifier(Qt::ControlModifier); customPlot->setNoAntialiasingOnDrag(true); customPlot->setOpenGl(true); customPlot->setPlottingHint(QCP::phFastPolylines, true); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); ``` 以上是使用 QCustomPlot 绘制实时波形的基本步骤,实际应用中,还可以根据需要进行细节调整和性能优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值