Qt-distinctive electronic clock

Source: Internet
Author: User

The electronic clock of QT is an old demo, but the display of lcdnumber is very old (the first display effect ), at first glance, we can see that the example is extracted from the QT help document and there is no new idea.

Beautify the system clock, put aside the inherent controls, and make the DIY effect eye-catching. Knowing the details determines the UI's success or failure. This is what I have been pursuing.

The idea is very simple, that is, the label or button texture is used to change the display.

When it comes to textures, some people may think of code redundancy, the amount of judgment and code for loading images by the hacker ...... In fact, pasters also focus on methods. For example, I have implemented one:

Getpngname (qchar X) is used to obtain the Resource Name, corresponding to the number 0123456789, that is, the resource image name is 0.png,1.png... and so on, so you only need:

QString Clock::getPngName(QChar x){     return (x+QString(".png") );}

You can. It's really easy ......

The code is just a few lines:

Clock::Clock(QWidget *parent) :    QWidget(parent),    ui(new Ui::Clock){    ui->setupUi(this);       timer = new QTimer(this);    connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));    timer->start(1000);    showTime();}Clock::~Clock(){    delete ui;}void Clock::showTime(){    //lcd    QTime time = QTime::currentTime();    QString text = time.toString("hh:mm:ss");    ui->lcdNumber->display(text);    //ourclock    ui->hourh->setIcon(QPixmap(this->getPngName(text[0])));    ui->hourl->setIcon(QPixmap(this->getPngName(text[1])));    ui->minh->setIcon(QPixmap(this->getPngName(text[3])));    ui->minl->setIcon(QPixmap(this->getPngName(text[4])));    ui->sech->setIcon(QPixmap(this->getPngName(text[6])));    ui->secl->setIcon(QPixmap(this->getPngName(text[7])));}QString Clock::getPngName(QChar x){     return (x+QString(".png") );}

In fact, the demo is very simple, and the focus is to change the ideas and methods of the display effect.

Any good ideas? Still the four words: Welcome to exchange ~~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.