马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 2015-11-20 20:00 编辑
代码://diginalclock.h
#ifndef DIGINALCLOCK_H
#define DIGINALCLOCK_H
#include <QLCDNumber>
class DiginalClock : public QLCDNumber
{
Q_OBJECT
public:
DiginalClock(QWidget *parent = 0);
private slots:
void showTime();
};
#endif // DIGINALCLOCK_H
================================//main.cpp
#include "diginalclock.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
DiginalClock w;
w.show();
return a.exec();
}
==========================
//diginalclock.cpp
#include "diginalclock.h"
#include <QtWidgets>
DiginalClock::DiginalClock(QWidget *parent)
: QLCDNumber(parent)
{
setSegmentStyle(Filled);
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
timer->start(1000);
showTime();
setWindowTitle(tr("Digtal Clock"));
resize(150,60);
}
void DiginalClock::showTime()
{
QTime time = QTime::currentTime();
QString text = time.toString("hh:mm");
if((time.second()%2) == 0)
text[2] = ' ';
display(text);
}
截图:
|