Qcustomplot是一个非常好用的第三方画图库,这里记录一下如何使用该IP。
第一步:下载文件
第二步:添加文件到工程
2.1在main函数的头文件中添加头文件:
#include "./qcustomplot/qcustomplot.h"
2.2 在pro文件中添加printsupport支持,这因为qt是5.0以上版本
QT += printsupport
第三步:提升widget为Qcustomplot类
void SCAN_ITU::customPlot_init_itu()
{
iq_data_i.resize(iq_data_length);
iq_data_q.resize(iq_data_length);
iq_data_x.resize(iq_data_length);
for (int i=0; i<iq_data_length; ++i)
{
iq_data_x[i] = i;
iq_data_i[i] = 16384*qCos(i*0.01);
iq_data_q[i] = 16384*qSin(i*0.01);
}
QLinearGradient plotGradient;
plotGradient.setStart(0, 0);
plotGradient.setFinalStop(0, 350);
plotGradient.setColorAt(0, QColor(50, 50, 50));
plotGradient.setColorAt(1, QColor(50, 50, 50));
customPlot_iq->setBackground(plotGradient);
customPlot_iq->xAxis->setTickLabelColor(Qt::white);
customPlot_iq->yAxis->setTickLabelColor(Qt::white);
customPlot_iq->xAxis->setBasePen(QPen(QColor(140, 140, 140),1));
customPlot_iq->yAxis->setBasePen(QPen(QColor(140, 140, 140),1));
customPlot_iq->xAxis2->setBasePen(QPen(QColor(140, 140, 140),1));
customPlot_iq->yAxis2->setBasePen(QPen(QColor(140, 140, 140),1));
customPlot_iq->addGraph();
customPlot_iq->graph(0)->setPen(QPen(Qt::green)); // line color blue for first graph
customPlot_iq->addGraph();
customPlot_iq->graph(1)->setPen(QPen(Qt::yellow)); // line color red for second graph
customPlot_iq->xAxis2->setVisible(true);
customPlot_iq->xAxis2->setTickLabels(false);
customPlot_iq->yAxis2->setVisible(true);
customPlot_iq->yAxis2->setTickLabels(false);
customPlot_iq->graph(0)->setData(iq_data_x, iq_data_i);
customPlot_iq->graph(1)->setData(iq_data_x, iq_data_q);
customPlot_iq->yAxis->setRange(-32768,32767);
customPlot_iq->xAxis->setRange(0,iq_data_length*IQ_FRAME_N);
// customPlot_iq->setInteractions(QCP::iRangeZoom );
}