2 #include <QTimer>
3 #include <QTime>
4 #include <QPalette>
5
6 myclock::myclock(QWidget* parent):QLCDNumber(parent)
7 {
8 //设定颜色
9 QPalette p = palette();
10 p.setColor(QPalette::Window,Qt::blue);
11 setPalette(p);
12
13 //隐藏标题,关闭按钮
14 setWindowFlags(Qt::FramelessWindowHint);
15 //设置透明度
16 setWindowOpacity(0.5);
17
//创建事件空间
18 QTimer *timer = new QTimer(this);
//与事件绑定
19 connect(timer,SIGNAL(timeout()),this,SLOT(showtime()));
//多长时间改变一次
20 timer->start(1000);
//显示时间
21 showtime();
22 resize(300,120);
23 }
24
25 void myclock::mousePressEvent(QMouseEvent *event)
26 {
27
28 }
29
30 void myclock::mouseMoveEvent(QMouseEvent *event)
31 {
32
33 }
34
35 void myclock::showtime()
36 {
37 QTime time = QTime::currentTime();//当前时间
38 QString str = time.toString("hh:mm:ss");//时间
39 this->display(str);
40 }