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 ~~~