#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())); }