Last active
July 30, 2018 19:42
-
-
Save blooser/8328eb21e1fb19bd08d950cb3d3559bd to your computer and use it in GitHub Desktop.
Digital Clock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "digitalshow.h" | |
#include <QDateTime> | |
#include <QPropertyAnimation> | |
#include <QGridLayout> | |
#include <QLabel> | |
#include <QGraphicsDropShadowEffect> | |
#include <QWindow> | |
DigitalShow::DigitalShow(QWidget * parent) | |
: QWidget(parent), | |
repeater(new QTimer), | |
digitalClock(new QLCDNumber){ | |
digitalClock->setSegmentStyle(QLCDNumber::Filled); | |
dotFormat = false; | |
digitalClock->display(QString("00:00")); | |
repeater->setInterval(1000); | |
repeater->start(); | |
connect(repeater, &QTimer::timeout, [this]{ | |
dotFormat = !dotFormat; | |
QString timeFormat = (dotFormat) ? QDateTime::currentDateTime().toString("hh:mm") | |
: QDateTime::currentDateTime().toString("hh mm"); | |
digitalClock->display(timeFormat); | |
}); | |
QString currentData = QDateTime::currentDateTime().toString("dd/MM/yyyy"); | |
auto currentDataLabel = new QLabel(currentData); | |
currentDataLabel->setStyleSheet("font: 40px; font-weight: 200;"); | |
auto dateLabelShadow = new QGraphicsDropShadowEffect; | |
dateLabelShadow->setOffset(QPoint(3, 4)); | |
dateLabelShadow->setBlurRadius(2); | |
currentDataLabel->setGraphicsEffect(dateLabelShadow); | |
QPropertyAnimation * animation; | |
animation = new QPropertyAnimation(this, "size"); | |
animation->setStartValue(QSize(0, 0)); | |
animation->setEndValue(QSize(360, 170)); | |
animation->start(); | |
auto mainLayout = new QGridLayout; | |
mainLayout->addWidget(digitalClock); | |
mainLayout->addWidget(currentDataLabel, 1, 0, Qt::AlignCenter); | |
setLayout(mainLayout); | |
setWindowTitle(tr("Digital Clock")); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DIGITALSHOW_H | |
#define DIGITALSHOW_H | |
#include <QLCDNumber> | |
#include <QTimer> | |
class DigitalShow : public QWidget { | |
Q_OBJECT | |
public: | |
DigitalShow(QWidget * parent = nullptr); | |
private: | |
QTimer * repeater = nullptr; | |
bool dotFormat; | |
QLCDNumber * digitalClock = nullptr; | |
}; | |
#endif // DIGITALSHOW_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include <QIcon> | |
#include "digitalshow.h" | |
int main(int argc, char ** argv){ | |
QApplication app(argc, argv); | |
QString iconName("icons/clock.png"); | |
QIcon appIcon(iconName); | |
app.setWindowIcon(appIcon); | |
DigitalShow clock; | |
clock.show(); | |
return app.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment