资源简介

Qt 自绘波形图 心电图 的 实时显示

资源截图

代码片段和文件信息

#include “autodrawline.h“
#includeyleOption>
#include
#include
#include

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(5y*20+20)QPoint(25y*20+20));
        p.drawText(6y*20QString::number(heightnum-y));//写数字
    }
    p.drawLine(QPoint(50)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)*20QString::number(x));
    }
    p.drawLine(QPoint(15(heightnum)*20)QPoint(width()(heightnum)*20));
//////////////////////////////////////////////////////////////////////////////////////
    if(m_isopen)
    {
        int x=0;
        for(int i=0;i        {
            if(i>=1)
            {
                QPoint point1(x+5m_list.at(i-1));
                QPoint point2(x+25m_list.at(i));
                p.setPen(Qt::yellow);
                p.drawLine(point1point2);
                qDebug()<            }
            x+=20;
        }
    }
    if(m_enter)
    {
        int x= this->mapFromGlobal(QCursor::pos()).x();
        p.setPen(Qt::yellow);
        p.drawLine(x0xheight());
    }
}
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(0xxx*20);
    if(m_list.count()>=100)
    m_list.removeLast();
    qDebug()<     update();
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2388  2016-06-07 12:53  WaveShapeDemo\autodrawline.cpp

     文件        516  2016-06-07 08:19  WaveShapeDemo\autodrawline.h

     文件        541  2016-06-07 13:09  WaveShapeDemo\dialog.cpp

     文件        307  2016-06-07 00:26  WaveShapeDemo\dialog.h

     文件        175  2016-06-07 00:25  WaveShapeDemo\main.cpp

     文件        395  2016-06-07 00:25  WaveShapeDemo\WaveShapeDemo.pro

     文件      23612  2016-06-07 13:10  WaveShapeDemo\WaveShapeDemo.pro.user

     目录          0  2016-06-07 13:10  WaveShapeDemo

----------- ---------  ---------- -----  ----

                27934                    8


评论

共有 条评论