qwt
一、
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的更多相关文章
- Qt编译安装qwt错误moc/xxx Error:126
		最近搞设计,需要在上位机上绘制曲线,在网上找了找,发现python的matplotlib和Qt的qwt都不错,本着难度最小原则,选择了Qt下面的qwt,安装过程中遇到了编译错误:moc/xxx Err ... 
- Qt之Qwt学习之安装
		QWT+qtcreator 编译.安装使用 目录:一.Qwt简介 二.QWT编译 一.Qwt简介 QWT:Qt Widgets for Technical Applications,是开源的2D绘图库 ... 
- Qt Qwt之坐标轴移动
		最近接触到个pro需要做到这方面,于是找了相关材料,也跟好些人讨论,目前就最简单的使用方法,通过按钮触发去控制 X,Y轴的移动,比例自己定义 这个是X轴放大的 QwtInterval tempInte ... 
- Qt Sqlite qwt 发布过程中碰到的问题runtime error
		qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ... 
- windows 7下qtcreator里QWT文件的pro配置
		http://blog.chinaunix.net/uid-20717410-id-272331.html 把编译好的qwt的include文件夹下面 所有的.h文件 复制到qt目录下 然后在pro里 ... 
- vs2012编译Qwt
		主题:vs2012编译Qwt ------------------------------------------------------------------------- 参照网络地址: htt ... 
- ubuntu QWT Qt
		1,下载QWT 2,解压进入QWT的目录 3,qmake,生成makefile文件 4,编译,make 5,安装,make install ,需要root 安装好后会在 /usr/local 目录下有 ... 
- qt creator中使用qwt插件
		前提:我用mingw编译的qwt. 将qwt插件集成到qt designer非常easy.仅仅要把qwt编译的qwt_designer_plugin.dll复制到C:\Qt\Qt5.3.1\5.3\m ... 
- linux安装qwt插件linux
		Optional: Get, Compile, Install QWT 5.0.0 (or newer): * NOTE: You should not need to set the environ ... 
- qt超强绘图控件qwt - 安装及配置
		qwt是一个基于LGPL版权协议的开源项目, 可生成各种统计图.它为具有技术专业背景的程序提供GUI组件和一组实用类,其目标是以基于2D方式的窗体部件来显示数据, 数据源以数值,数组或一组浮点数等方式 ... 
随机推荐
- mysql 5.7 版本 You must reset your password using ALTER USER statement before executing this statement报错处理
			https://blog.csdn.net/muziljx/article/details/81541896 MySQL版本5.7.6版本开始的用户可以使用如下命令: mysql> ALTER ... 
- python_网络编程socket(TCP)
			服务端: import socket sk = socket.socket() #创建对象 sk.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) ... 
- C++ extern关键字
			[参考] 关于C++中extern的简单笔记 
- 网络和Web编程
			一.以客户端的形式同HTTP服务交互 (1)使用urllib.request模块发送HTTP GET请求 from urllib import request,parse url = 'http:// ... 
- RabbitMq、ActiveMq、Kafka和Redis做Mq对比
			转载自:https://blog.csdn.net/qiqizhiyun/article/details/79848834 一.RabbitMq RabbitMQ是一个Advanced Message ... 
- leetcode解题报告(10):Merge Two Sorted Lists
			描述 Merge two sorted linked lists and return it as a new list. > The new list should be made by sp ... 
- [Luogu] 开关
			https://www.luogu.org/problemnew/show/P3870 线段树区间翻转 + 区间查询 #include <iostream> #include <cs ... 
- [Luogu] 贪婪大陆
			https://www.luogu.org/problemnew/show/P2184 区间修改时只需修改区间端点的numl或numr值 区间查询x-y只需用1-y的numr - 1-(x - 1)的 ... 
- Qt ASSERT:"QMetaObjectPrivate::get(smeta)->revision>= 7"in file kernel\qobject.cpp,line 2646
			qt5.6.1所做的工程在运行时出现该问题:该问题说的是信号槽中 函数的参数不匹配. 在qt4.8.4 中QThread 中查到assitant中定义void QThread::finished () ... 
- 关于scala
			对函数式编程感兴趣了 雪下scala吧 
