1、QCustomPlot介绍
QCustomPlot is a Qt C++ widget for plotting and data visualization. It has no further dependencies and is well documented. This plotting library focuses on making good looking, publication quality 2D plots, graphs and charts, as well as offering high performance for realtime visualization applications. Have a look at the Setting Up and the Basic Plotting tutorials to get started.
QCustomPlot can export to various formats such as vectorized PDF files and rasterized images like PNG, JPG and BMP. QCustomPlot is the solution for displaying of realtime data inside the application as well as producing high quality plots for other media.
2、QCustomPlot的下载
QCustomPlot官网链接:https://www.qcustomplot.com/index.php/introduction
下载链接:https://www.qcustomplot.com/index.php/download
我这里以1.0.1版本进行学习,所以点击上图红框部分,即可下载完全安装包,包括源码,文档,帮助文件等。
3、QCustomPlot的使用
3.1、新建一个Qt界面程序
创建好后,项目结构如下:
3.2、将QCustomPlot源码文件添加到项目里
将下载好的压缩文件QCustomPlot.tar.gz拷贝到项目目录里,然后进行解压。
我这里解压到QCustomPlot文件夹下,这样文件不会很乱。
QCustomPlot文件夹下包含如下文件:
其中:
- qcustomplot.h和qcustomplot.cpp是源码文件
- documentation是文档目录
- examples是案例目录
将qcustomplot.h和qcustomplot.cpp添加到项目里,添加后项目结构如下:
3.2.1、控件提升法
双击mainwindow.ui界面文件,在UI Designer中,可以拖动一个Widget控件到ui设计器上,对这个窗体点击右键,选择提升为:
在提升的窗口部件窗口里,输入如下信息:
然后,依次点击添加、提升按钮。
提升后,窗体对象列表如下:
这里将centralWidget使用水平布局,widget改名为customPlot。修改后的窗体对象列表如下:
运行:
3.2.2、直接使用法
直接使用法指的是在使用QCustomPlot文件的地方,直接包含头文件,然后程序里显示的创建QCustomPlot控件。
代码:
QCustomPlot *customPlot=new QCustomPlot;
QHBoxLayout *mainLayout=new QHBoxLayout;
mainLayout->addWidget(customPlot);
ui->centralWidget->setLayout(mainLayout);
setWindowTitle("直接使用法");
运行: