一、

1.下载地址https://sourceforge.net/projects/qwt/

2.注意:官方提供qt安装包creator都是用MSVC编译(包括mingW版)的,所以Creator的插件,必须使用MSVC编译,才能被识别。插件用什么编译的,建立项目就要使用对应的编译,才能识别出来。要想使用mingw,需要下载qt源代码用mingw编译安装。

3.用Qt打开qwt.pro,选择MSVC2017_32bit编译。

4.把生成的文件\designer\plugins\designer\qwt_designer_plugin.dll 复制到D:\ProgramFiles\Qt5.13.2\Tools\QtCreator\bin\plugins\designer 下面,打开Qt界面设计就可以看到有此插件。

5.lib\qwt.dll和lib\qwtd.dll 复制到D:\ProgramFiles\Qt5.13.2\5.13.2\msvc2017\bin; lib\qwt.lib和lib\qwtd.lib复制到D:\ProgramFiles\Qt5.13.2\5.13.2\msvc2017\lib;

6.在D:\ProgramFiles\Qt5.13.2\5.13.2\msvc2017\include新建一个文件qwt,把所有的头文件拷贝到此目录下。

7.新建Qt项目,在pro添加DEFINES += QT_DLL QWT_DLL

库引用:

win32:CONFIG(release, debug|release): LIBS += -LD:/ProgramFiles/Qt5./msvc2017/lib/ -lqwt
/msvc2017/lib/ -lqwtd

INCLUDEPATH += D:/ProgramFiles/Qt5./msvc2017/include/qwt
DEPENDPATH += D:/ProgramFiles/Qt5./msvc2017/include/qwt

二、

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <QVector>
#include "qwt/qwt_plot.h"
#include "qwt/qwt_plot_curve.h"
#include "qwt/qwt_plot_grid.h"
#include "qwt/qwt_legend.h"
#include "qwt/qwt_plot_zoomer.h"
#include "qwt/qwt_plot_magnifier.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void qwtPlotTest();
private:
    Ui::MainWindow *ui;
private:
    QVector<double> xData;
    QVector<double> yData;
    QTimer updateTimer;
    QString demoName;
    QwtPlotCurve *curve;
    double getData(double interval);
    void showRealtimeData(QwtPlot *qwtPlot);
private slots:
    void slotUpdatedData();

    void on_pbUpdateData_clicked();
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QTime>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->qwtPlot->move(,);
    ui->qwtPlot->resize(,);
   // qwtPlotTest();
    showRealtimeData(ui->qwtPlot);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::qwtPlotTest()
{
    ;
    ;

    //qDebug()<<width<<height;
    //移动QwtPlot控件到父窗口的0,0起始位
    ui->qwtPlot->move(,);
    //设置QwtPlot控件的大小
    ui->qwtPlot->resize(width,height);

    //参数是QString
    //ui->qwtPlot->setTitle(QObject::trUtf8("QwtPlot Test"));
    QwtText t;
    //设置标题名
    t.setText(QObject::trUtf8("QwtPlot Test"));
    //设置字体
    QFont font;
    //设置粗体
    font.setBold(true);
    //设置斜体
    font.setItalic(true);
    t.setFont(font);
    //设置颜色
    t.setColor(QColor(,,));

    //设置标题背景色
    QBrush brush(QColor(,,));
    t.setBackgroundBrush(brush);

    ui->qwtPlot->setTitle(t);

    //设置纵坐标
    //第一个参数表示坐标轴,
    //第二个参数表示坐标轴最小值
    //第三个参数表示坐标轴最大值
    //第四个参数表示步进
    //QwtPlot有四条坐标轴,分别对应如下
    //左坐标轴  QwtPlot::yLeft
    //右坐标轴  QwtPlot::yRight
    //底部坐标轴 QwtPlot::xBottom
    //顶部坐标轴 QwtPlot::xTop

    ui->qwtPlot->enableAxis(QwtPlot::yRight,true);
    ui->qwtPlot->enableAxis(QwtPlot::xTop,true);

    qDebug()<<ui->qwtPlot->axisEnabled(QwtPlot::yLeft);
    qDebug()<<ui->qwtPlot->axisEnabled(QwtPlot::xBottom);
    qDebug()<<ui->qwtPlot->axisEnabled(QwtPlot::yRight);
    qDebug()<<ui->qwtPlot->axisEnabled(QwtPlot::xTop);

    ui->qwtPlot->setAxisScale(QwtPlot::yLeft,,,);
    ui->qwtPlot->setAxisScale(QwtPlot::xBottom,,,);
    ui->qwtPlot->setAxisScale(QwtPlot::yRight,,,);
    ui->qwtPlot->setAxisScale(QwtPlot::xTop,,,);

    ui->qwtPlot->setAxisTitle(QwtPlot::yLeft,QObject::trUtf8("Left"));
    ui->qwtPlot->setAxisTitle(QwtPlot::yRight,QObject::trUtf8("Right"));
    ui->qwtPlot->setAxisTitle(QwtPlot::xBottom,QObject::trUtf8("Bottom"));
    ui->qwtPlot->setAxisTitle(QwtPlot::xTop,QObject::trUtf8("Top"));

    //微软雅黑
    //黑体
    QFont f();//Helvetica [Cronyx]
    ui->qwtPlot->setAxisFont(QwtPlot::xBottom,f);

    //数据x,y值保存
    QVector<QPointF> vector;
    ;i<;i++){
        QPointF point;
        point.setX(i);
        *sin(i*M_PI/) + ;
        point.setY(y);
        vector.append(point);
    }
    //构造曲线数据
    QwtPointSeriesData* series = new QwtPointSeriesData(vector);

    //create plot item
    QwtPlotCurve* curve1 = new QwtPlotCurve("Curve 1");
    //设置数据
    curve1->setData(series);
    //设置画笔
    curve1->setPen(QColor(,,),,Qt::SolidLine);
    //设置填充画刷
    QBrush brush2(QColor(,,));
    curve1->setBrush(brush2);
    //使曲线更光滑
    curve1->setCurveAttribute(QwtPlotCurve::Fitted, true);
    //把曲线附加到qwtPlot上
    curve1->attach(ui->qwtPlot);

    //数据x,y值保存
    QVector<QPointF> vector2;
    ;i<;i++){
        QPointF point;
        point.setX(i);
        *sin(i*M_PI/) + ;
        point.setY(y);
        vector2.append(point);
    }
    //构造曲线数据
    QwtPointSeriesData* series2 = new QwtPointSeriesData(vector2);
    //create plot item
    QwtPlotCurve* curve2 = new QwtPlotCurve("Curve 2");
    //设置数据
    curve2->setData(series2);
    //设置画笔
    curve2->setPen(QColor(,,),,Qt::DotLine);
    //设置填充画刷
    QBrush brush3(QColor(,,));
    curve2->setBrush(brush3);
    //把曲线附加到qwtPlot上
    curve2->attach(ui->qwtPlot);

    //加入网格
    QwtPlotGrid* grid = new QwtPlotGrid();
    grid->setPen(QColor(,,),);
    grid->attach(ui->qwtPlot);

    //删除所画的图形
    //curve1->detach();
    //curve2->detach();

    ui->qwtPlot->replot();
    ui->qwtPlot->show();
}

void MainWindow::showRealtimeData(QwtPlot *qwtPlot)
{
    //初始化xdata,x对应长度为5的坐标,y初始全为0
//    for(int i=1;i<5001;i++){
//       xData.append(double(i)/1000-5);
//       yData.append(0);
//    }

    demoName = "Real Time Data Demo";
    qwtPlot->setTitle(demoName);
    qwtPlot->setCanvasBackground(Qt::gray);//背景
    qwtPlot->insertLegend(new QwtLegend(),QwtPlot::RightLegend);//标签

    curve = new QwtPlotCurve();
    curve->setTitle("肌电信号");//曲线名字
    curve->setPen( Qt::yellow,  );//曲线的颜色 宽度;

    QTime curtime;
    curtime=curtime.currentTime();
    qwtPlot->setAxisTitle(QwtPlot::xBottom, "x- System Uptime");
    qwtPlot->setAxisTitle(QwtPlot::yLeft,"y-EMG");
    qwtPlot->setAxisScale(QwtPlot::yLeft,-,,);
    qwtPlot->setAxisScale(QwtPlot::xBottom,-,,);

    QwtPlotZoomer *zoomer = new QwtPlotZoomer( qwtPlot->canvas() );
    zoomer->setRubberBandPen( QColor( Qt::blue ) );
    zoomer->setTrackerPen( QColor( Qt::black ) );
    zoomer->setMousePattern(QwtEventPattern::MouseSelect2,Qt::RightButton, Qt::ControlModifier );
    zoomer->setMousePattern(QwtEventPattern::MouseSelect3,Qt::RightButton );
   //默认的滑轮及右键缩放功能  图形的整体缩放
    QwtPlotMagnifier *magnifier = new QwtPlotMagnifier( qwtPlot->canvas() );
    //设置哪个按钮与滑轮为缩放画布  如果不设置(注册掉当前行)按钮默认为滑轮以及右键为缩放
    //magnifier->setMouseButton(Qt::LeftButton);

    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->enableX( true );//设置网格线
    grid->enableY( true );
    grid->setMajorPen( Qt::black, , Qt::DotLine );
    grid->attach(qwtPlot);

    connect(&updateTimer,SIGNAL(timeout()),this,SLOT(slotUpdatedData()));
    updateTimer.start();
}

double MainWindow::getData(double time)
{
    ) ;
    return s;

}
void MainWindow::slotUpdatedData()
{
    static QTime dataTime(QTime::currentTime());
    long int eltime = dataTime.elapsed();
    ;

    int size = (eltime - lastpointtime);

    ){//有数据传入
        yData.erase(yData.begin(),yData.begin()+size);//擦除多余的数据
        ;i<size+;i++){
            yData.append(getData(((()));
        }
        lastpointtime = eltime;
    }

    curve->setSamples(xData,yData);
    curve->attach(ui->qwtPlot);
    ui->qwtPlot->replot();
}

void MainWindow::on_pbUpdateData_clicked()
{
    //y:-2,2,1  -5,0,1
    )
    {
        yData.erase(yData.begin(),yData.begin()+);
    }
    yData.append(-);
    yData.append();
    yData.append(-);

    xData.append(-);
    xData.append(-);
    xData.append(-);

    curve->setSamples(xData,yData);
    curve->attach(ui->qwtPlot);
    ui->qwtPlot->replot();

}

qwt的更多相关文章

  1. Qt编译安装qwt错误moc/xxx Error:126

    最近搞设计,需要在上位机上绘制曲线,在网上找了找,发现python的matplotlib和Qt的qwt都不错,本着难度最小原则,选择了Qt下面的qwt,安装过程中遇到了编译错误:moc/xxx Err ...

  2. Qt之Qwt学习之安装

    QWT+qtcreator 编译.安装使用 目录:一.Qwt简介 二.QWT编译 一.Qwt简介 QWT:Qt Widgets for Technical Applications,是开源的2D绘图库 ...

  3. Qt Qwt之坐标轴移动

    最近接触到个pro需要做到这方面,于是找了相关材料,也跟好些人讨论,目前就最简单的使用方法,通过按钮触发去控制 X,Y轴的移动,比例自己定义 这个是X轴放大的 QwtInterval tempInte ...

  4. Qt Sqlite qwt 发布过程中碰到的问题runtime error

    qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ...

  5. windows 7下qtcreator里QWT文件的pro配置

    http://blog.chinaunix.net/uid-20717410-id-272331.html 把编译好的qwt的include文件夹下面 所有的.h文件 复制到qt目录下 然后在pro里 ...

  6. vs2012编译Qwt

    主题:vs2012编译Qwt ------------------------------------------------------------------------- 参照网络地址: htt ...

  7. ubuntu QWT Qt

    1,下载QWT 2,解压进入QWT的目录 3,qmake,生成makefile文件 4,编译,make 5,安装,make install ,需要root 安装好后会在 /usr/local 目录下有 ...

  8. qt creator中使用qwt插件

    前提:我用mingw编译的qwt. 将qwt插件集成到qt designer非常easy.仅仅要把qwt编译的qwt_designer_plugin.dll复制到C:\Qt\Qt5.3.1\5.3\m ...

  9. linux安装qwt插件linux

    Optional: Get, Compile, Install QWT 5.0.0 (or newer): * NOTE: You should not need to set the environ ...

  10. qt超强绘图控件qwt - 安装及配置

    qwt是一个基于LGPL版权协议的开源项目, 可生成各种统计图.它为具有技术专业背景的程序提供GUI组件和一组实用类,其目标是以基于2D方式的窗体部件来显示数据, 数据源以数值,数组或一组浮点数等方式 ...

随机推荐

  1. gorm 更新数据时,0值会被忽略

    原文: https://www.tizi365.com/archives/22.html ------------------------------------------------------- ...

  2. AutoMapper 的简单使用

    var config = new MapperConfiguration( cfg => cfg.CreateMap<SYS_Menu, MenuTreeNode>() .ForMe ...

  3. linux实操_组管理

    1.文件/目录的所有者 一般为文件的创建者,谁创建了该文件,就自然成为该文件的所有者. 查看文件的所有者: 指令:ls -ahl 修改文件所有者: 指令:chown 用户名 文件名 组的创建: 指令: ...

  4. Github:VS使用GitHub要点

    1.VS打开[扩展或更新]安装插件[Github Extension for VisualStudio] 2.在团队资源管理中可以Clone线上已经有的库到本地,或者可以新建库同步到线上 3.同步设置 ...

  5. 【概率论】1-2:计数方法(Counting Methods)

    title: [概率论]1-2:计数方法(Counting Methods) categories: Mathematic Probability keywords: Counting Methods ...

  6. (转)python正向连接后门

    python正向连接后门 PHITHON 2014 四月 12 00:12   阅读:16670    Python    python, cmd后门, socket     python在linux ...

  7. windows游戏编程X86 32位保护模式下的内存管理概述(二)

    本系列文章由jadeshu编写,转载请注明出处.http://blog.csdn.net/jadeshu/article/details/22448323 作者:jadeshu   邮箱: jades ...

  8. Django基础之中间件

    1. 引入 在之前学习的过程中,已经学会了给视图函数加装饰器来判断用户是否登录,把没有登录的用户请求跳转到登录页面. 我们通过给几个特定视图函数加装饰器实现了这个需求. 但是以后添加的视图函数可能也需 ...

  9. Python2.7编码问题:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position...解决方法

    解决方法: 在Python程序最前面加上以下语句: import sys reload(sys) sys.setdefaultencoding('utf-8')

  10. Java中的集合Collection

    集合是什么? Java集合类存放于 java.util 包中,是一个用来存放对象的容器. 注意:①.集合只能存放对象.比如你存一个 int 型数据 1放入集合中,其实它是自动转换成 Integer 类 ...