QCustomPlot的下载和安装

Qt的图形有Qt自带的QChart 但是它只能画一些简单的和静态的,而QCustomPlot比它强大一点,比较复杂和动态的它都可以,比较流畅。
下载和安装
QCustomPlot官网:
https://www.qcustomplot.com/index.php/download
下载最新版本:
在这里插入图片描述
下载后解压,有以下文件:
在这里插入图片描述
打开documentation文件夹
在这里插入图片描述
将里面的qcustomplot.qch文件放到你Qt安装目录中Docs目录 ,如下图:
在这里插入图片描述
打开Qt Create -> 工具 -> 选项 然后按如下图的流程
在这里插入图片描述
以上就安装好QCustomPlot的帮助文档,以后就可以按F1查看相关的函数,或直接搜索。

测试安装是否成功
在Qt Create中新建一个工程,右键创建的工程 添加现有的文件
在.pro文件中加入模块 QT += printsupport
在这里插入图片描述
在这里插入图片描述
把这两个文件加到工程中 如下图
在这里插入图片描述
在ui文件中添加一个widget
在这里插入图片描述
右击控件提升
在这里插入图片描述
然后编译,如果没有错误就下一步

然后在官网中将例子的代码复制到mainwindow.cpp构造函数中
官网:https://www.qcustomplot.com/index.php/tutorials/basicplotting

QCustomPlot* customPlot  = ui->widget;  //这个是我加的,ui-> + 自己的在ui文件中控件的类名 
// add two new graphs and set their look:
customPlot->addGraph();
customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
// generate some points of data (y0 for first, y1 for second graph):
QVector<double> x(251), y0(251), y1(251);
for (int i=0; i<251; ++i)
{
  x[i] = i;
  y0[i] = qExp(-i/150.0)*qCos(i/10.0); // exponentially decaying cosine
  y1[i] = qExp(-i/150.0);              // exponential envelope
}
// configure right and top axis to show ticks but no labels:
// (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
customPlot->xAxis2->setVisible(true);
customPlot->xAxis2->setTickLabels(false);
customPlot->yAxis2->setVisible(true);
customPlot->yAxis2->setTickLabels(false);
// make left and bottom axes always transfer their ranges to right and top axes:
connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
// pass data points to graphs:
customPlot->graph(0)->setData(x, y0);
customPlot->graph(1)->setData(x, y1);
// let the ranges scale themselves so graph 0 fits perfectly in the visible area:
customPlot->graph(0)->rescaleAxes();
// same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
customPlot->graph(1)->rescaleAxes(true);
// Note: we could have also just called customPlot->rescaleAxes(); instead
// Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

运行,成功就会出现如下图:
在这里插入图片描述
以上步骤官网也有,但是我感觉这个比详细一点。

  • 10
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值