-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome_window.cpp
55 lines (50 loc) · 1.38 KB
/
home_window.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
#include "home_window.h"
HomeWindow::HomeWindow() {
}
/**
* @author xinhaichen
* 初始化窗口及控件
*/
void HomeWindow::setupUi() {
setWindowTitle("闪烁");
m_button = new QPushButton("开始闪烁");
m_blinkButton = new QPushButton("button");
QVBoxLayout *baseLayout = new QVBoxLayout();
setLayout(baseLayout);
baseLayout->addWidget(m_blinkButton, 1);
baseLayout->addWidget(m_button,1);
resize(200,200);
BlinkThread *blinkThread = new BlinkThread;
connect(m_button, SIGNAL(clicked()),this,SLOT(buttonClick()));
connect(blinkThread, SIGNAL(blinkSignal()), this, SLOT(doBlink()));
QObject::connect(blinkThread, SIGNAL(finished()), blinkThread, SLOT(deleteLater()));
blink = false;
blinkThread->start();
}
/**
* 闪烁
*/
void HomeWindow::buttonClick() {
count = 0;
blink = !blink;
if (blink){
m_button->setText("停止闪烁");
} else {
m_button->setText("开始闪烁");
}
}
void HomeWindow::doBlink() {
if (blink) {
qInfo("--doBlink--");
count++;
QString stylesheet;
if (count %3==0){
stylesheet = "background-color:#00AEEC;";
} else if (count %3==1){
stylesheet = "background-color:#B03060;";
} else {
stylesheet = "background-color:#03A89E;";
}
m_blinkButton->setStyleSheet(stylesheet);
}
}