QCustomPlot的使用方法

来源:互联网 发布:天津师范大学软件学院 编辑:程序博客网 时间:2024/06/11 01:57

1. 官网下载

去官网下载,最新的版本,地址:http://www.qcustomplot.com/
目前最新的是2.0.0 Beta版本,使用起来和老版差不多。





2. 使用方法

(1)将压缩包解压,得到2个文件:qcustomplot.h  和  qcustomplot.cpp,放入项目文件夹。


(2)如下图所示,在pro文件里, 添加内容:printsupport





(3)操作ui

为了能在ui designer里面使用QCustomPlot,可以拖动一个Widget控件到ui设计器上,

对这个窗体点击右键,选择提升为:




把提升的类名填写为QCustomPlot即可,这样就可以使用了,
使用就和我们用普通控件一样,ui->xxx->……





3. 显示图像

(1)重命名你托上去的widget控件,例如 :customPlot




(2)编码

在项目自动生成的代码里面,增加1个函数,例如叫 : showchart();







在showchart()函数中,添加显示图像的代码:






编译,运行,结果:



代码如下:
void Dialog::showchart(){    // generate some data:    QVector<double> 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:    ui->customPlot->addGraph();    ui->customPlot->graph(0)->setData(x, y);    // give the axes some labels:    ui->customPlot->xAxis->setLabel("x");    ui->customPlot->yAxis->setLabel("y");    // set axes ranges, so we see all data:    ui->customPlot->xAxis->setRange(-1, 1);    ui->customPlot->yAxis->setRange(0, 1);    ui->customPlot->replot();}




完成!
-------------

原创粉丝点击