QT心电图设计
2024-10-13 10:04:54
不需要别的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();
timer = new QTimer(this);
//timer的超时时间与处理函数链接起来,时间来刷新槽函数
connect(timer,SIGNAL(timeout()),this,SLOT(timer_timeout()));
//启动定时器
timer->start();
} MainWindow::~MainWindow()
{
delete ui;
} void MainWindow::paintEvent(QPaintEvent *event)
{
//todo 界面刷新时,执行 将点连成线RER
//准备画笔
QPainter painter(this);
QPen pen;
pen.setWidth();//设置画刷的像素宽度
pen.setBrush(QBrush(Qt::green));//设置画刷的颜色
painter.setPen(pen);
painter.setRenderHint(QPainter::Antialiasing);//画刷抗锯齿
int i;
for(i=;i<point_arry.size();i++){
QPoint p1=point_arry[i-]; //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 = ;//static 下次不在从零开始
int y;
if(x<this->width()){//如果x现在在主窗口的宽度内
y = this->height()/+rand()%-;//y轴移动的取值,将y值放在height中间
point_arry.push_back(QPoint(x,y));//point_arry的类型就是QPoint类型的
x+=;//每次移动的x轴长度
}
else{//如果x轴的长度超出窗口的长度
int i;
for(i=;i<point_arry.size();i++){
point_arry[i-].setY(point_arry[i].y());//将arry中y的值与上一个y值交换
}
point_arry[point_arry.size()-].setY(this->height()/+rand()%-);//设置目前的y值
}
this->update();
}
最新文章
- 【ipv6惹的祸】curl 超时
- 将golang程序注册为windows服务
- 关于“float”的一次探索--遇到了一个span元素可以设置宽高引发的思考
- Grunt设置
- .bss 段 block started symbol
- Windows 7中使用Eclipse 使用CDT and WinGW 开发C/C++(转载)
- 六步实现Spring.NET 与 NHibernate 的整合
- C++字符串之一(字符表示)
- centos6.5 x86_64安装oracle 11.2.0.3grid
- MySql开启远程访问(Linux)
- Android数据库--Sqlcipher的使用(一)
- extjs Proxy
- HTTP各个status code是什么意思【已解决】
- 关于ML.NET v0.7的发布说明
- MySQL字符串列与整数比较
- C#中,使用正则表达式匹配获取所需数据
- Mybatis学习4——多对一
- inception+archery SQL审核平台
- IIS URL Rewrite Module的防盗链规则设置
- 总结java中的super和this关键字