#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
t1 = new QTimer(this);
connect(t1,&QTimer::timeout,this,&Widget::on_timeout);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_StartBtn_clicked()
{
ui->textEdit->hide();
t1->start(1000);
if(ui->block->text() == ui->CurrentTime)
{
ui->textEdit->show();
}
}
void Widget::on_timeout()
{
//获取系统当前时间
QTime sys_t = QTime::currentTime();
//将系统时间转化为字符串
QString time = sys_t.toString("hh:mm:ss");
if(showFlag)
{
time[2] = ':';
showFlag = false;
}
else {
time[2] = ' ';
showFlag = true;
}
ui->CurrentTime->display(time);
}
void Widget::on_StopBtn_clicked()
{
t1->stop();
}