QT C++ QCustomPlot 简单使用

//本文描述QCustomPlot的简单使用,

//使用QCustomPlot 画曲线分5步

//1.初始化

//2.发送

//3.接收

//4.绑定

//5.重绘

//通常单独的线程发送,发送线程通过emit函数或者wake(WakeOne)函数告诉接收方,

//接收方通常是GUI类的函数,把数据放进vector容器

//定时绑定vector容器和重绘,可以比第2步和第3步慢(因为我们有vector容器装好了的)

//在2、3、4、5步循环往复。

//1.初始化

struct CurveInfo

{

QString nameX;// X轴label

QString nameY;// Y轴label

double minX;//X轴最小

double minY;//Y轴最小

double maxX;//X轴最大

double maxY;//Y轴最大

};

initCurve(QCustomPlot* plot, CurveInfo curveInfo)

{

plot->setBackground(QBrush(QColor(220, 220, 220)));//背景灰

plot->addGraph();

plot->graph(0)->setPen(QPen(Qt::blue));//画笔颜色

plot->xAxis->setLabel(curveInfo.nameX);//X轴颜色

plot->yAxis->setLabel(curveInfo.nameY);//Y轴颜色

// 支持鼠标拖拽轴的范围、滚动缩放轴的范围,左键点选图层(每条曲线独占一个图层)

plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

plot->xAxis->setRange(curveInfo.minX, curveInfo.maxX);

plot->yAxis->setRange(curveInfo.minY, curveInfo.maxY);

// 设置坐标系格栅背景

// plot->xAxis->grid()->setPen(QPen(Qt::darkGreen));

// plot->yAxis->grid()->setPen(QPen(Qt::darkGreen));

plot->xAxis->grid()->setSubGridVisible(true);//X栅格可见

plot->yAxis->grid()->setSubGridVisible(true);/Y栅格可见

//坐标内背景

plot->axisRect()->setBackground(QBrush(QColor(30, 30, 30)));

plot->replot();

}

//2.发送

//用信号的emit函数或者QwaitCondition的wakeOne()函数

//3.接收

//如果使用QwaitCondition,那么要单独搞个接收线程,GUI是不太可能有死循环的。

//4.绑定

//绑定函数的原型是,第1个参数是横轴对应容器,第2参数是纵轴对应容器,第三个参数可不写

void setData(const QVector<double> &keys,

const QVector<double> &values,

bool alreadySorted=false

);

//5.重绘

//重绘函数的原型是

void replot();

其余可参考

QCustomPlot 曲线各种属性设置介绍_customplot在曲线上添加实心圆点-CSDN博客CustomPlot 曲线各种属性设置介绍_customplot在曲线上添加实心圆点-CSDN博客QCustomPlot 曲线各种属性设置介绍_customplot在曲线上添加实心圆点-CSDN博客

相关推荐
SNAKEpc121386 分钟前
QML和Qt Quick
c++·qt
PH_modest6 分钟前
【Qt跬步积累】—— 初识Qt
开发语言·qt
hansang_IR16 分钟前
【题解】洛谷 P4286 [SHOI2008] 安全的航线 [递归分治]
c++·数学·算法·dfs·题解·向量·点积
GanGuaGua25 分钟前
Linux系统:线程的互斥和安全
linux·运维·服务器·c语言·c++·安全
怀旧,33 分钟前
【C++】18. 红⿊树实现
开发语言·c++
lsnm34 分钟前
【LINUX网络】IP——网络层
linux·服务器·网络·c++·网络协议·tcp/ip
宁静致远20211 小时前
【C++设计模式】第三篇:观察者模式(别名:发布-订阅模式、模型-视图模式、源-监听器模式)
c++·观察者模式·设计模式
xiaopengbc1 小时前
在 Python 中实现观察者模式的具体步骤是什么?
开发语言·python·观察者模式
Python大数据分析@1 小时前
python用selenium怎么规避检测?
开发语言·python·selenium·网络爬虫
ThreeAu.1 小时前
Miniconda3搭建Selenium的python虚拟环境全攻略
开发语言·python·selenium·minicoda·python环境配置