#include "autodrawline.h"
#include<QStyleOption>
#include<QPainter>
#include<QDebug>
#include<QTime>
autodrawline::autodrawline(QWidget *parent) : QWidget(parent)
{
setStyleSheet("background: black;");
m_isopen=false;
m_enter=false;
setMouseTracking(true);
}
void autodrawline::paintEvent(QPaintEvent *)
{
QStyleOption opt; opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
static QColor color(Qt::red);
int heightnum= height()/20;//每格相间20px
for(int y=0;y<=heightnum;y++)//绘y轴
{
p.setPen(color);
p.drawLine(QPoint(5,y*20+20),QPoint(25,y*20+20));
p.drawText(6,y*20,QString::number(heightnum-y));//写数字
}
p.drawLine(QPoint(5,0),QPoint(5,(heightnum)*20));//画竖线
int widthnum= width()/10;//每格相间20px
for(int x=0;x<=widthnum;x++)//绘x轴
{
p.drawLine(QPoint(20*x+5,(heightnum)*20),QPoint(20*x+5,(heightnum)*20-10));
p.drawText(20*x+6,(heightnum)*20,QString::number(x));
}
p.drawLine(QPoint(15,(heightnum)*20),QPoint(width(),(heightnum)*20));
//////////////////////////////////////////////////////////////////////////////////////
if(m_isopen)
{
int x=0;
for(int i=0;i<m_list.count();i++)//刷新
{
if(i>=1)
{
QPoint point1(x+5,m_list.at(i-1));
QPoint point2(x+25,m_list.at(i));
p.setPen(Qt::yellow);
p.drawLine(point1,point2);
qDebug()<<point1<<point2;
}
x+=20;
}
}
if(m_enter)
{
int x= this->mapFromGlobal(QCursor::pos()).x();
p.setPen(Qt::yellow);
p.drawLine(x,0,x,height());
}
}
void autodrawline::mouseMoveEvent(QMouseEvent *)
{
m_enter=true;
update();
}
void autodrawline::leaveEvent(QEvent*)
{
m_enter=false;
update();
}
void autodrawline::slot_timer()//无论给多少个update()都不会影响画图 只是多m_list
{
m_isopen=true;
QTime time;
time= QTime::currentTime();
qsrand(time.msec()+time.second()*1000);
int xxx=qrand()%height()/20;
m_list.insert(0,xxx*20);
if(m_list.count()>=100)
m_list.removeLast();
qDebug()<<m_list.count();
update();
}
Qt 自绘波形图 心电图 的 实时显示
4星 · 超过85%的资源 需积分: 34 97 浏览量
2016-06-07
13:14:11
上传
评论 22
收藏 5KB RAR 举报
小乌龟在大乌龟背上
- 粉丝: 954
- 资源: 27
最新资源
- NetOps-py通过sftp替换网络设备启动文件
- STM32单片机FPGA毕设电路原理论文报告任务驱动教学法在单片机课程教学中的应用
- STM32单片机FPGA毕设电路原理论文报告任务驱动法在单片机教学中的应用
- STM32单片机FPGA毕设电路原理论文报告人造金刚石压机智能化压力测控系统设计
- 以某列为依据匹配多项(Excel版)
- STM32单片机FPGA毕设电路原理论文报告人体短臂离心机实验台的显示控制系统
- STM32单片机FPGA毕设电路原理论文报告人工气候室监控系统的环境控制器研究
- STM32单片机FPGA毕设电路原理论文报告染整自动线张力控制系统的设计
- 数据挖掘与机器学习-实验
- 基于Linux系统Nginx的动态网站的LNMP环境源码包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页