Qtday4

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置时间居中显示
    ui->edt->setFont(QFont("宋体", 50, 30, false));

    //给语音播报申请空间
    speecher = new QTextToSpeech(this);

    ui->label->setText("睡尼玛,起来嗨");
    ui->label->setAlignment(Qt::AlignCenter);
    ui->label->setFont(QFont("宋体", 50, 30, false));

}

void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId() == t1)
    {
        //显示的系统时间
        //获取当前系统时间
        t = QTime::currentTime();
        ui->timelab1->setText(t.toString("hh:mm:ss"));
        //设置时间居中显示
        ui->timelab1->setAlignment(Qt::AlignCenter);
        ui->timelab1->setFont(QFont("宋体", 50, 30, false));
    }
    //闹铃
    if(t.toString("hh:mm:ss") == ui->edt->text())
    {
        int i = 0;
        while(i < 60)
        {
            speecher->say(ui->label->text());
            i++;
        }
    }
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_startbtn_clicked()
{
    //按下启动一个定时器
    t1 = startTimer(1000);
}


void Widget::on_stopbtn_clicked()
{
    speecher->stop();
}

Qtday4_第1张图片

Qtday4_第2张图片

你可能感兴趣的:(c++)