10.20QT作业

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);//纯净窗口
    ui->label2->setPixmap(QPixmap("D:\\QT\\picture\\daiwei2.jpg"));//呆唯
    ui->label2->setScaledContents(true);

    ui->lineEdit->setPlaceholderText("几点?");

    ui->label3->setText("看看你的");
    ui->label3->setAlignment(Qt::AlignCenter);
    ui->label3->setFont(QFont("宋体",30,30,false));


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




}

void Widget::timerEvent(QTimerEvent *event)
{
    if(event->timerId()==tid)
    {
        QTime sys_time=QTime::currentTime();
        QString s=sys_time.toString("hh::mm::ss");
        //将系统时间放入标签中
        ui->label1->setText(s);
        //居中显示
        ui->label1->setAlignment(Qt::AlignCenter);
        ui->label1->setFont(QFont("宋体", 30, 30, false));
        if(ui->lineEdit->text() == ui->label1->text())
                {
                    int i = 0;
                    while(i < 3)
                    {
                        speecher->say(ui->label3->text());
                        i++;
                    }

                }


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


void Widget::on_btn3_clicked()
{
    this->close();
}

void Widget::on_btn1_clicked()
{

    tid=startTimer(1000);

}

void Widget::on_btn2_clicked()
{
    killTimer(tid);
}
#ifndef WIDGET_H
#define WIDGET_H

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    int t;
    void timerEvent(QTimerEvent *event);
private slots:
    void on_btn3_clicked();
    void on_btn1_clicked();

    void on_btn2_clicked();

private:
    Ui::Widget *ui;
    int tid;
    //定义一个语音播报者
    QTextToSpeech *speecher;
};
#endif // WIDGET_H

10.20QT作业_第1张图片

你可能感兴趣的:(qt,开发语言)