mywnd.h
#ifndef MYWND_H
#define MYWND_H
#include <QWidget>
#include<QPushButton>
#include <QTextToSpeech>
class Mywnd : public QWidget
{
Q_OBJECT
public slots:
void sayMes();
public:
Mywnd(QWidget *parent = nullptr);
~Mywnd();
//定义一个按钮指针
QPushButton *keyong;
QPushButton *bofang;
QPushButton *guanbi;
//定义一个播报者
QTextToSpeech speech;
};
#endif // MYWND_H
mywnd.cpp
#include "mywnd.h"
#include<QDebug>
Mywnd::Mywnd(QWidget *parent): QWidget(parent)
{
this->resize(1024,768);//重新设置主控件大小
this->setWindowTitle("播放器");
//背景颜色
this->setBackgroundRole(QPalette::Dark);
this->setAutoFillBackground(true);
keyong=new QPushButton(this);
keyong->resize(150,50);
keyong->move(100,height()/2);
keyong->setText("可用");
bofang=new QPushButton(this);
bofang->resize(150,50);
bofang->move(100+keyong->width(),height()/2);
bofang->setText("播放");
guanbi=new QPushButton(this);
guanbi->resize(150,50);
guanbi->move(100+keyong->width()+bofang->width(),height()/2);
guanbi->setText("关闭");
connect(bofang,&QPushButton::clicked,this,&Mywnd::sayMes);
connect(bofang,&QPushButton::clicked,this,[=](){
bofang->setEnabled(false);
});
connect(keyong,&QPushButton::clicked,this,[=](){
bofang->setEnabled(true);
});
connect(guanbi,&QPushButton::clicked,this,[=](){
this->close();
});
}
void Mywnd::sayMes()
{
speech.say(guanbi->text());
}
Mywnd::~Mywnd()
{
}