qcustomplot在Linux开发板,QCustomplot的使用以及编译动态链接库的过程

本文介绍了如何在Linux开发板上使用QCustomPlot,包括创建QCustomPlot对象,设置数据,调整坐标轴范围,以及自定义刻度。同时,详细阐述了将QCustomPlot编译为arm-linux动态链接库.so的步骤,涉及交叉编译工具链和符号链接的处理。

#ifndef _HLM_GRAPH_H_

#define _HLM_GRAPH_H_

#include 

class hlm_temp_Graph : public QWidget

{

public:

explicit hlm_temp_Graph(QWidget *parent = 0);

~hlm_temp_Graph();

bool set_XY_Vector_value(QVector &, QVector &);

private:

QCustomPlot *customplot;

};

#endif // HLM_GRAPH_H#include "hlm_graph.h"

#include 

hlm_temp_Graph::hlm_temp_Graph(QWidget *parent) : QWidget(parent)

{

customplot = new QCustomPlot(this);

this->resize(800, 480);

customplot->resize(350, 130);

customplot->move(440, 310);

}

bool hlm_temp_Graph::set_XY_Vector_value(QVector &X_Vectorcount, QVector &Y_Vectortemp)

{

QVector Y_tempTickVertor(7); //y轴温度大刻度数组

for ( int i = 0; i 

{

Y_tempTickVertor[i] = i * 5;

}

for ( int i = 0; i 

{

X_Vectorcount[i] = i + 1;   //将来用来代表x轴上第几次采集温度的次数

}

QCPGraph *graph1 = customplot->addGraph();

graph1->setData(X_Vectorcount, Y_Vectortemp);   //设置曲线上关联的数据,温度次数数组,温度值数组

customplot->yAxis->setRange(0, 30);     //y轴的范围 0-30 摄氏度

customplot->xAxis->setRange(1, X_Vectorcount.size());     //x轴的范围 1-20次

customplot->xAxis->setAutoTicks(false); //x轴设置为不自动提供刻度位置

customplot->yAxis->setAutoTicks(false); //y轴设置为不自动提供刻度位置

customplot->xAxis->setTickVector(X_Vectorcount);   //x轴的刻度点,使用count数组中的刻度

customplot->yAxis->setTickVector(Y_tempTickVertor);   //y轴的刻度点,使用tempTickVertor数组中的刻度点

customplot->xAxis->setLabel(QString::fromUtf8("采集/次")); //设置x轴的标签名字

customplot->yAxis->setLabel(QString::fromUtf8("温度/℃")); //设置y轴的标签名字

//graph1->setPen(QPen(QColor(255, 74, 15), 2));   //设置曲线本身的颜色 2为占两个像素

graph1->setPen(QPen(Qt::NoPen));                  //设置曲线本身颜色不可见

graph1->setBrush(QColor(255, 116, 21, 125));        //设置graph1曲线覆盖面积的颜色 125为透明度,透明度上限为255

customplot->xAxis->setSubTickPen(QPen(Qt::NoPen));  //设置x轴中小刻度没有画笔颜色,则小刻度的本身标线看不到

customplot->yAxis->setSubTickPen(QPen(Qt::NoPen));  //设置y轴中小刻度没有画笔颜色,则小刻度的本身标线看不到

customplot->xAxis->grid()->setPen(QPen(Qt::NoPen)); //设置x轴绘制网格线颜色的笔(大刻度位置对应的网格线)Qt::NoPen表示没有画笔颜色,则x轴大刻度位置的网格线看不到

customplot->yAxis->grid()->setPen(QPen(QColor(227, 227, 227), Qt::SolidLine));  //设置y轴大刻度线位置对应网格线的颜色,Qt::SolidLine表示网格线为实线

QLinearGradient plotGradient;       //线性渐变画笔

plotGradient.setStart(0, 310);        //设置线性渐变的起点

plotGradient.setFinalStop(0, 440);  //设置线性渐变的结束点

plotGradient.setColorAt(0, QColor(243, 243, 243)); //设置线性渐变颜色的起点的颜色

plotGradient.setColorAt(1, QColor(50, 50, 50)); //设置线性渐变颜色的终点的颜色,起点和终点之间的颜色用0的颜色到1的颜色进行渐变,0和1表示整体的起始位置和结束位置

customplot->setBackground(plotGradient);    //设置背景色为该线性渐变的颜色

}

hlm_temp_Graph::~hlm_temp_Graph()

{

delete customplot;

}#include "mainwindow.h"

#include 

#include "hlm_graph.h"

int main(int argc, char *argv[])

{

QApplication a(argc, argv);

//    MainWindow w;

//    w.show();

QVector X_Vectorcount(20), Y_Vectortemp(20); //Vectorcount温度次数数组,Vectortemp温度数组,tempTickVertor y轴温度大刻度数组

Y_Vectortemp[0] = 20.5;

Y_Vectortemp[1] = 22.5;

Y_Vectortemp[2] = 22.5;

Y_Vectortemp[3] = 25.5;

Y_Vectortemp[4] = 28.5;

Y_Vectortemp[5] = 26.5;

Y_Vectortemp[6] = 23.5;

Y_Vectortemp[7] = 21.5;

Y_Vectortemp[8] = 25.5;

Y_Vectortemp[9] = 26.5;

Y_Vectortemp[10] = 27.5;

Y_Vectortemp[11] = 25.5;

Y_Vectortemp[12] = 23.5;

Y_Vectortemp[13] = 24.5;

Y_Vectortemp[14] = 24.5;

Y_Vectortemp[15] = 24.5;

Y_Vectortemp[16] = 26.5;

Y_Vectortemp[17] = 26.5;

Y_Vectortemp[18] = 27.5;

Y_Vectortemp[19] = 27.5;

hlm_temp_Graph temp_grap;

temp_grap.set_XY_Vector_value(X_Vectorcount, Y_Vectortemp);

temp_grap.show();

return a.exec();

}

前提是从http://www.qcustomplot.com/index.php/support/documentation下载QCustomPlot - v1.0.zip将qcustomplot.cpp qcustomplot.h放入到Qt的工程中。

如果想要有其对应的ui控件,在ui设计中,选择一个Widget组件,然后将Widget组件提升为QCustomPlot即可,之后就可以ui->customplot形式去操作这个Qcustomplot的了

编译动态链接库的方法:

如果要编译成arm-linux版本的动态连接库.so形式的,我使用的方法是首先确定你的交叉编译工具链是arm-linux-gcc的,然后将下载下来的QCustomPlot-sharedlib.tar.gz放入到虚拟机中除了共享目录下的一个目录中,之后将qcustomplot.cpp qcustomplot.h放入到和QCustomPlot-sharedlib.tar.gz所在的同目录下,然后解压QCustomPlot-sharedlib.tar.gz,进入sharedlib-compilation目录中,先qmake,然后make,之后GNU/LINUX使用的.so动态链接库就出来了,之后使用cp *so* xxx/ -rdf 的方式将动态链接库拷贝到除了共享目录外的一个目录下,然后压缩成压缩包,之后放入到文件夹形式的文件系统中,解压即可。rdf是为了让符号连接被拷贝过后还是符合连接。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值