侧边栏壁纸
博主头像
三味的小站博主等级

世界上没有偶然,有的只是必然的结果。

  • 累计撰写 61 篇文章
  • 累计创建 13 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录
Qt

QCustomPlot简单使用

三味线
2018-12-10 / 0 评论 / 0 点赞 / 13 阅读 / 2478 字

下载

官网下载并解压:https://www.qcustomplot.com/

使用

  1. 创建一个QMainWindow应用,注意添加Print Support模块(.pro中Qt += printsupport);

  1. qcustomplot.hqcustomplot.cpp复制到项目目录,并添加到项目中;

  2. 添加代码如下:

#ifndef CPLOT0_H
#define CPLOT0_H
#include <QtWidgets/QMainWindow>
#include "ui_cplot0.h"
#include "qcustomplot.h"
class cplot0 : public QMainWindow
{
    Q_OBJECT
public:
    cplot0(QWidget *parent = 0);
    ~cplot0();
    void simpledemo(QCustomPlot *customPlot);
private:
    Ui::cplot0Class ui;
};
#endif // CPLOT0_H
#include "cplot0.h"
#include <QVector>
#include <QtMath>
cplot0::cplot0(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    this->setCentralWidget(ui.widget);
    simpledemo(ui.widget);
}
cplot0::~cplot0()
{
}
void cplot0::simpledemo(QCustomPlot *customPlot)
{
    QVector<double> x, y;
    for (double i=-10; i <= 10; i=i+0.1)
    {
        double x1 = i;
        double y1 = qSin(i) * 100;
        x.append(x1);
        y.append(y1);
    }
    customPlot->addGraph();
    customPlot->graph(0)->setPen(QPen(Qt::red));
    customPlot->graph(0)->setLineStyle(QCPGraph::lsImpulse);
    customPlot->graph(0)->setData(x, y);
    customPlot->xAxis->setLabel("time");
    customPlot->yAxis->setLabel("value");
    customPlot->xAxis->setRange(-10, 10);
    customPlot->yAxis->setRange(-100, 100);
}
  1. 效果:

  2. 参考官网的示例:https://www.qcustomplot.com/index.php/introduction

0

评论区