QT学习day4

 作业:做一个闹钟

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

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

    //给定时器指针实例化一个对象
    timer = new QTimer(this);

    //给语音播报者实例化一个空间
    speecher = new QTextToSpeech(this);


    //将该定时器的timeout信号链接到自定义的槽函数中
    //connect(timer,&QTimer::timeout,this,&Widget::timeout_slot);

    this->setWindowTitle("闹钟小能手");
    this->setWindowIcon(QIcon(":/pictrue/R-C.png"));


    //窗口
    QPixmap background(":/pictrue/bd315c6034a85edf9c8a4d994f540923dd547501.jpg");

    // 创建一个QPalette对象,并将背景图像设置为窗口背景
    QPalette palette;
    palette.setBrush(this->backgroundRole(), QBrush(background));
    this->setPalette(palette);

    // 将窗口的背景模式设置为固定尺寸
    this->setAutoFillBackground(true);

    /********************************************************************************/
    //    //设置闹钟背景
    //    //  ui->Qlable->setPixmap(QPixmap(":/pictrue/bd315c6034a85edf9c8a4d994f540923dd547501.jpg"));
    //    //    //自动适应标签
    //    //    ui->Qlable->setScaledContents(true);


    //按钮设计
    ui->btn1->setIcon(QIcon(":/pictrue/R-C.png"));
    ui->btn1->setWindowOpacity(0.9);
    ui->btn2->setIcon(QIcon(":/pictrue/R-C.jfif"));

    //标签设计
    ui->Lable1->setPixmap(QPixmap(":/pictrue/R-C.png"));
    //自动适应标签
    ui->Lable1->setScaledContents(true);
    ui->Lable1->setWindowOpacity(0.9);

    //标签设计
    ui->Lable2->setPixmap(QPixmap(":/pictrue/R-C.jfif"));
    //自动适应标签
    ui->Lable2->setScaledContents(true);
    ui->Lable2->setWindowOpacity(0.9);


}

Widget::~Widget()
{
    delete ui;
}
void Widget::timerEvent(QTimerEvent *e)//定时器处理事件
{
    if(e->timerId()==timer_id)
    {
        QTime s=QTime::currentTime();//获取系统时间
        //将QTime类对象转换为字符串
        QString t=s.toString("hh:mm:ss");

        //展示到ui界面
        ui->Lable1->setText(t);

        //居中显示
        ui->Lable1->setAlignment(Qt::AlignCenter);

        //设置字体
        // 创建一个字体对象
        QFont font("Arial", 30, QFont::Bold);

        // 设置标签的字体
        ui->Lable1->setFont(font);

        //接收输入的文本
        QString v = ui->lineEdit->text();

        if(t==v)
        {
            //speecher->say(ui->Lable3->text());


            int i=0;//播报十遍
            while( i=10)
            {
                speecher->say(ui->textEdit->toPlainText());
                i++;

            }

        }



     }

}



void Widget::on_btn1_clicked()//启动按钮
{
    //启动一个定时器,超过时间和自动调用定时器事件处理函数
    timer_id=this->startTimer(1000);
}

void Widget::on_btn2_clicked()//停止按钮
{
    //关闭给定的定时器
    this->killTimer(timer_id);


}


效果图: 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值