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方式的窗体部件来显示数据, 数据源以数值,数组或一组浮点数等方式 ...
随机推荐
- solr query没有反应,地址报错查询的地址error
随便修改了一下angular.js,保存,再修改,就可以查询了 问题应该是对文件没有操作权限.感觉solr在部署时对文件的授权还是很重要的
- 详解Python 切片语法
Python的切片是特别常用的功能,主要用于对列表的元素取值.这篇文章主要介绍了详解Python 切片语法,需要的朋友可以参考下 Python的切片是特别常用的功能,主要用于对列表的元素取值.使用切片 ...
- spring配置和映射文件
配置 <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www. ...
- BZOJ 5495: [2019省队联测]异或粽子 (trie树)
这题果然是原题[BZOJ 3689 异或之].看了BZOJ原题题解,发现自己sb了,直接每个位置维护一个值保存找到了以这个位置为右端点的第几大,初始全部都是1,把每个位置作为右端点能够异或出来的最大值 ...
- 分页控件Webdiyer.MvcPager
MVC 1.安装控件 install-package Webdiyer.MvcPager 2.Cotroller using System; using System.Collections.Gene ...
- winfrom 遍历文本框
//winform中Control是所有组件的基类 ; i <= ; i++) { Control[] coltxtSpeed = this.Controls.Find("txtbox ...
- 配置阿里yum源
root@docker ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/epel-7.rep ...
- 使List<userClass>.Contains可以查找重復的對象
List.Contains实现对比 http://blog.csdn.net/yswucn/article/details/4091469
- 在Android中使用OpenGL ES进行开发第(二)节:定义图形
一.前期基础知识储备笔者计划写三篇文章来详细分析OpenGL ES基础的同时也是入门关键的三个点: ①OpenGL ES是什么?与OpenGL的关系是什么?——概念部分 ②使用OpenGLES绘制2D ...
- Ubuntu14.04 系统复制迁移到新的机器上
1.打包系统文件 制作启动盘,然后进入bios, #进入bios的boot标签选择sandisk启动 如果没有找到u盘进入save & exit标签页选择boot override中的sand ...