d61c94341
김태훈
디지털 시계 추가
|
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
|
#include "digitalclock.h"
#include <QTimer>
#include <QDateTime>
DigitalClock::DigitalClock(QWidget *parent) : QLabel(parent)
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(updateView()));
updateView();
timer->start(100);
}
void DigitalClock::updateView()
{
static const QString format("\
<style>\
span.time { color: white; font-size: 15pt; font-weight: bold; }\
span.date { color: #C3C3C3; font-size: 12pt; }\
</style>\
<span class=\"time\">%1:%2</span><br><span class=\"date\">%3, %4 %5</span>");
QDateTime dt = QDateTime::currentDateTime();
setText(format
.arg(dt.time().hour(), 2, 10, QLatin1Char('0'))
.arg(dt.time().minute(), 2, 10, QLatin1Char('0'))
.arg(QDate::longDayName(dt.date().dayOfWeek()))
.arg(QDate::longMonthName(dt.date().month()))
.arg(dt.date().day()));
}
|