forked from feiyangqingyun/QWidgetDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmlightbutton.cpp
56 lines (48 loc) · 1.39 KB
/
frmlightbutton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma execution_character_set("utf-8")
#include "frmlightbutton.h"
#include "ui_frmlightbutton.h"
#include "qdatetime.h"
#include "qtimer.h"
frmLightButton::frmLightButton(QWidget *parent) : QWidget(parent), ui(new Ui::frmLightButton)
{
ui->setupUi(this);
this->initForm();
}
frmLightButton::~frmLightButton()
{
delete ui;
}
void frmLightButton::initForm()
{
ui->lightButton2->setBgColor(QColor(255, 107, 107));
ui->lightButton3->setBgColor(QColor(24, 189, 155));
type = 0;
QTimer *timer = new QTimer(this);
timer->setInterval(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(updateValue()));
timer->start();
updateValue();
//以下方法启动报警
//ui->lightButton1->setAlarmColor(QColor(255, 0, 0));
//ui->lightButton1->setNormalColor(QColor(0, 0, 0));
//ui->lightButton1->startAlarm();
}
void frmLightButton::updateValue()
{
if (type == 0) {
ui->lightButton1->setLightGreen();
ui->lightButton2->setLightRed();
ui->lightButton3->setLightBlue();
type = 1;
} else if (type == 1) {
ui->lightButton1->setLightBlue();
ui->lightButton2->setLightGreen();
ui->lightButton3->setLightRed();
type = 2;
} else if (type == 2) {
ui->lightButton1->setLightRed();
ui->lightButton2->setLightBlue();
ui->lightButton3->setLightGreen();
type = 0;
}
}