Qt Creator 二维绘图库QCustomPlot的使用

编程入门 行业动态 更新时间:2024-10-26 16:23:52

<a href=https://www.elefans.com/category/jswz/34/1769097.html style=Qt Creator 二维绘图库QCustomPlot的使用"/>

Qt Creator 二维绘图库QCustomPlot的使用

本文主要包含三个内容:QCustomPlot的加载、在主窗口绘图、在子窗口绘图

QCustomPlot的加载

1.下载链接[click here]

2.解压(解压到哪都行)

  • documentation文档
  • example示例(看示例比看文档有用)
  • changelog更新日志
  • *.cpp *.h这两个文件需要添加到自己的.pro文件中才可以画图

3.添加*.cpp *.h到工程文件

  1. 添加 *.cpp *.h到工程文件
  2. Qt 5 需要添加下面语句
QT       +=  printsupport

4.在需要的地方[主窗口/子窗口]包含头文件

#include "qcustomplot.h"

QCustomPlot主窗口绘图

  1. 在ui文件中添加widget
  2. 提升为QCustomPlot

  1. 更改QCustomPlot的变量名为customplot

  1. *.h头文件声明绘图函数
public:void setupQuadraticDemo(QCustomPlot *customPlot);
  1. *.cpp文件中定义函数
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);setupQuadraticDemo(ui->customplot);ui->customplot->replot();
}Widget::~Widget()
{delete ui;}void Widget::setupQuadraticDemo(QCustomPlot *customPlot)
{// generate some data:QVector<double> x(101), y(101); // initialize with entries 0..100for (int i=0; i<101; ++i){x[i] = i/50.0 - 1; // x goes from -1 to 1y[i] = x[i]*x[i];  // let's plot a quadratic function}// create graph and assign data to it:customPlot->addGraph();customPlot->graph(0)->setData(x, y);// give the axes some labels:customPlot->xAxis->setLabel("x");customPlot->yAxis->setLabel("y");// set axes ranges, so we see all data:customPlot->xAxis->setRange(-1, 1);customPlot->yAxis->setRange(0, 1);}

效果展示

QCustomPlot子窗口绘图

子窗口绘图步骤和主窗口一样,唯一多一步就是要把子窗口绘制的图挂载在主窗口上,整个流程分为两步
(1)挂载子窗口[click here]
(2)模仿主窗口绘图

更多推荐

Qt Creator 二维绘图库QCustomPlot的使用

本文发布于:2024-02-27 14:38:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1706931.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Qt   Creator   QCustomPlot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!