#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
id = startTimer(1000);
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *e)
{
if(e->timerId()==id)
{
ui->sys_lab->setAlignment(Qt::AlignCenter);//居中显示
QTime sys_time = QTime::currentTime();//获取当前时间
QString time = sys_time.toString("hh:mm:ss");//将获取的时间转换为字符串类型
ui->sys_lab->setText(time);
ui->clock_lab->setAlignment(Qt::AlignCenter);
ui->lineEdit->setAlignment(Qt::AlignCenter);
if(ui->clock_lab->text()==ui->sys_lab->text())//当设置的闹钟到点时执行以下语句
{
ui->txt_lab->setText("好好学习,天天向上");
ui->txt_lab->setAlignment(Qt::AlignCenter);
}
}
else
{
killTimer(id);
}
}
void Widget::on_pushButton_clicked()
{
QString clock = ui->lineEdit->text();
ui->clock_lab->setText(clock);
}
QT 周末
最新推荐文章于 2024-11-07 14:27:51 发布