zoukankan      html  css  js  c++  java
  • QT心电图设计

    不需要别的UI设置,直接放在QT文件中即可

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QTimer>//定时器头文件
    #include <QVector>//容器头文件
    #include <QPainter>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        //explicit显式构造,避免隐式构造
        explicit MainWindow(QWidget *parent = nullptr); //构造函数
        ~MainWindow();//析构函数
    
    private:
        Ui::MainWindow *ui;
        QTimer *timer;//定时器
        QVector<QPoint> point_arry;//保存所有的坐标容器
        //界面刷新的时候,会自动调用函数
        void paintEvent(QPaintEvent *event);
        //定时器处理函数
    public slots:
        //定义槽函数
        void timer_timeout(void);
    
    };
    
    #endif // MAINWINDOW_H
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        //初始化变量
        qsrand(3);
        timer = new QTimer(this);
        //timer的超时时间与处理函数链接起来,时间来刷新槽函数
        connect(timer,SIGNAL(timeout()),this,SLOT(timer_timeout()));
        //启动定时器
        timer->start(100);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::paintEvent(QPaintEvent *event)
    {
        //todo 界面刷新时,执行 将点连成线RER
        //准备画笔
        QPainter painter(this);
        QPen pen;
        pen.setWidth(2);//设置画刷的像素宽度
        pen.setBrush(QBrush(Qt::green));//设置画刷的颜色
        painter.setPen(pen);
        painter.setRenderHint(QPainter::Antialiasing);//画刷抗锯齿
        int i;
        for(i=1;i<point_arry.size();i++){
            QPoint p1=point_arry[i-1]; //p1 等于point_arry上一点
            QPoint p2=point_arry[i];   //p2 等于point_arry目前的点
            painter.drawLine(p1,p2);//将p1与p2链接起来
        }
    
    }
    //槽函数的实现
    void MainWindow::timer_timeout()
    {
        //todo 定时器到时执行的任务 移动Y轴
        static int x = 0;//static 下次不在从零开始
        int y;
        if(x<this->width()){//如果x现在在主窗口的宽度内
            y = this->height()/2+rand()%200-100;//y轴移动的取值,将y值放在height中间
            point_arry.push_back(QPoint(x,y));//point_arry的类型就是QPoint类型的
            x+=5;//每次移动的x轴长度
        }
        else{//如果x轴的长度超出窗口的长度
            int i;
            for(i=1;i<point_arry.size();i++){
                point_arry[i-1].setY(point_arry[i].y());//将arry中y的值与上一个y值交换
            }
            point_arry[point_arry.size()-1].setY(this->height()/2+rand()%200-100);//设置目前的y值
        }
        this->update();
    }
  • 相关阅读:
    将文件夹压缩为jar包——JAVA小工具
    android json解析及简单例子(转载)
    Eclipse RCP中获取Plugin/Bundle中文件资源的绝对路径(转载)
    右键菜单的过滤和启动(转载)
    eclipse rcp应用程序重启
    使用PrefUtil设置全局配置
    模拟器屏幕大小
    Android实现下载图片并保存到SD卡中
    PhoneGap与Jquery Mobile组合开发android应用的配置
    android WebView结合jQuery mobile之基础:整合篇
  • 原文地址:https://www.cnblogs.com/sailifsh-lyh/p/10645940.html
Copyright © 2011-2022 走看看