当前位置: 首页 > news >正文

做网站要不要营业执照网站销售怎么推广

做网站要不要营业执照,网站销售怎么推广,b站推广费,网页制作教程视频下载文章目录 1 定时器事件1.1 界面布局1.2 关联信号槽1.3 重写timerEvent1.4 实现槽函数 启动定时器 2 定时器类 项目完整的源代码 QT中使用定时器,有两种方式: 定时器类:QTimer定时器事件:QEvent::Timer,对应的子类是QTi…

文章目录

  • 1 定时器事件
    • 1.1 界面布局
    • 1.2 关联信号槽
    • 1.3 重写timerEvent
    • 1.4 实现槽函数 启动定时器
  • 2 定时器类

在这里插入图片描述

项目完整的源代码

QT中使用定时器,有两种方式:

  • 定时器类:QTimer
  • 定时器事件:QEvent::Timer,对应的子类是QTimerEvent

1 定时器事件

1.1 界面布局

把两个标签以及“启动”、“停止"、“复位”三个按钮布局在界面上。

首先,来到timer_widget.h,声明两个标签:

// timer_widget.h
private:QLabel *lbl1;QLabel *lbl2;

timer_widget.cpp 中 实现布局

// timer_widget.cppTimerWidget::TimerWidget(QWidget* parent) : QWidget{parent} {QVBoxLayout* verticalLayout = new QVBoxLayout(this);verticalLayout->setSpacing(0);verticalLayout->setContentsMargins(0, 0, 0, 0);// 第一个标签控件lbl1 = new QLabel(this);lbl1->setFrameShape(QFrame::Box);lbl1->setFixedSize(100, 100);lbl1->setStyleSheet("background-color: red;");verticalLayout->addWidget(lbl1);// 第二个标签控件lbl2 = new QLabel(this);lbl2->setFrameShape(QFrame::Box);lbl2->setFixedSize(100, 100);lbl2->setStyleSheet("background-color: blue;");verticalLayout->addWidget(lbl2);// 添加水平布局 - 三个按钮QHBoxLayout* horizontalLayout = new QHBoxLayout(this);horizontalLayout->setSpacing(0);horizontalLayout->setContentsMargins(0, 0, 0, 0);verticalLayout->addLayout(horizontalLayout);QPushButton* btnStart = new QPushButton(this);QPushButton* btnStop = new QPushButton(this);QPushButton* btnReset = new QPushButton(this);btnStart->setText("开始");btnStop->setText("停止");btnReset->setText("复位");horizontalLayout->addWidget(btnStart);horizontalLayout->addWidget(btnStop);horizontalLayout->addWidget(btnReset);this->setStyleSheet(R"(QPushButton {font-Size: 22px;})");connect(btnStart, &QPushButton::clicked, this,&TimerWidget::onStartClicked);connect(btnStop, &QPushButton::clicked, this, &TimerWidget::onStopClicked);connect(btnReset, &QPushButton::clicked, this,&TimerWidget::onResetClicked);
}

1.2 关联信号槽

关联按钮与槽函数

// 点击按钮触发开启定时器函数
connect(btnStart, &QPushButton::clicked, this,&TimerWidget::onStartClicked);
// 点击按钮触发关闭定时器函数connect(btnStop, &QPushButton::clicked, this, &TimerWidget::onStopClicked);
// 点击按钮触发标签复位connect(btnReset, &QPushButton::clicked, this,&TimerWidget::onResetClicked);

1.3 重写timerEvent

timer_widget.cpp 文件中重写timerEvent函数

// timer_widget.cppvoid TimerWidget::timerEvent(QTimerEvent* event) {// id1 的时间为 10ms 时间到了 做这件事if (event->timerId() == id1) {lbl1->move(lbl1->x() + 5, lbl1->y());if (lbl1->x() > this->width()) {lbl1->move(0, lbl1->y());}// id2 的时间为 20ms 时间到了 做这件事} else if (event->timerId() == id2) {lbl2->move(lbl2->x() + 5, lbl2->y());if (lbl2->x() > this->width()) {lbl2->move(0, lbl2->y());}}
}

1.4 实现槽函数 启动定时器

timer_widget.cpp

void TimerWidget::onStartClicked() {// 启动定时器 - timerEvent// 时间到了自动执行timerEvent函数id1 = startTimer(10);  // 10msid2 = startTimer(20);
}void TimerWidget::onStopClicked() {killTimer(id1);killTimer(id2);
}void TimerWidget::onResetClicked() {lbl1->move(0, lbl1->y());lbl2->move(0, lbl2->y());
}

2 定时器类

接下来,使用定时器类QTimer来实现以上同样的效果

首先,在timer_widget.h声明两个定时器类的对象,以及定时超时的槽函数:

// timer_widget.h
private slots:void onTimerout1();void onTimerout2();private:QTimer *timer1;QTimer *timer2;

然后,在timer_widget.cpp中实现两个定时超时槽函数:

// timer_widget.cpp
void TimerWidget::onTimerout1() {lbl1->move(lbl1->x() + 5, lbl1->y());if (lbl1->x() > this->width()) {lbl1->move(0, lbl1->y());}
}void TimerWidget::onTimerout2() {lbl2->move(lbl2->x() + 5, lbl2->y());if (lbl2->x() > this->width()) {lbl2->move(0, lbl2->y());}
}

关联结束时间信号触发槽

// timer_widget.cpptimer1 = new QTimer(this);timer2 = new QTimer(this);connect(timer1, &QTimer::timeout, this, &TimerWidget::onTimerout1);connect(timer2, &QTimer::timeout, this, &TimerWidget::onTimerout2);

实现槽函数 启动定时器

void TimerWidget::onStartClicked() {timer1->start(10);timer2->start(20);
}void TimerWidget::onStopClicked() {timer1->stop();timer2->stop();
}
http://www.dinnco.com/news/50615.html

相关文章:

  • 建设维护网站运营方案十大营销模式
  • 镇江外贸型网站建设咖啡的营销推广软文
  • 如何起手做网站项目seo推广薪资
  • 石家庄招聘哪个网站做的好百度地图轨迹导航
  • 南京电子商务网站建设网店
  • 有创意的30个网站北京百度关键词排名
  • 傻瓜式建站平台本地推广平台有哪些
  • 学校网站建设目标郑州网络推广公司
  • 南通网站建设有限公司百度竞价冷门产品
  • 做5g网站百度搜索引擎的特点
  • html5网站制作编辑源码全部列表支持安卓浏览器软件下载
  • 海宁网站开发app推广刷量
  • 互联网网站建设公司杭州小周seo
  • 网站目录提交seo技术教程网
  • 如何建设公司网站知乎今天刚刚的最新新闻
  • 海口网站建设 小黄网络简单网页设计模板html
  • 深圳网站建设分期付百度推广注册
  • 单页式网站网络营销师主要做什么
  • 网站的竞争对手上海网站营销推广
  • 网站怎么放香港空间乔拓云智能建站官网
  • 有哪些网站建设工作百度网页游戏中心
  • 淘宝客网站推广备案信息网络营销推广方式包括哪几种
  • 网站建设一条龙服务我想做电商怎么加入
  • 创新的医疗网站建设semifinal
  • 武汉做网站的公司网站公司的肇庆百度快速排名
  • dw软件做的东西怎么在网站用外贸独立站怎么做
  • 怎么做企业网址seo平台是什么
  • 制作付款网站系统优化大师官方下载
  • 做网站需要什么系统外贸营销网站制作
  • html5企业网站赏析seo怎么收费的