首页 > 其他分享 >Qt实现页面时钟显示

Qt实现页面时钟显示

时间:2022-12-09 14:34:18浏览次数:43  
标签:Qt text 页面 timer QTimer time include DigitalClock 时钟


#include <QtWidgets>

#include "digitalclock.h"

DigitalClock::DigitalClock(QWidget *parent)
: QLCDNumber(parent)
{
setSegmentStyle(Filled);

QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &DigitalClock::showTime);
timer->start(1000);

showTime();

setWindowTitle(tr("Digital Clock"));
resize(150, 60);
}

void DigitalClock::showTime()
{
QTime time = QTime::currentTime();
QString text = time.toString("hh:mm");
if ((time.second() % 2) == 0)
text[2] = ' ';
display(text);
}

#include <QApplication>

#include "digitalclock.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
DigitalClock clock;
clock.show();
return app.exec();
}

结果显示:

Qt实现页面时钟显示_页面显示

Qt实现页面时钟显示_时钟_02

标签:Qt,text,页面,timer,QTimer,time,include,DigitalClock,时钟
From: https://blog.51cto.com/u_15515702/5925174

相关文章