#include "mywnd.h"
#include<QDebug>
#include <QTextToSpeech>
void mywnd::showMes()
{
static int i = 1;
this->btn2->setText(QString::number(i++));
//speech.say(btn2->text());
}
//处理自定义信号的槽函数
void mywnd::say_mes()
{
speech.say(btn2->text());
btn1->setEnabled(false);
}
//退出
void mywnd::say_t()
{
speech.say(btn2->text());
close();
}
mywnd::mywnd(QWidget *parent)
: QWidget(parent)
{
this->resize(1024, 768); //重新设置主控件大小
this->setMaximumSize(1500, 1000); //设置最大尺寸
this->setMinimumSize(500,200); //设置最小尺寸
this->setFixedSize(500,500); //设置固定尺寸
//设置窗口标题
this->setWindowTitle("FirstWindow");
//获取标题
QString title = this->windowTitle(); //得到窗口标题
qDebug()<<title;
//设置背景色
// this->setBackgroundRole(QPalette::Dark);
// this->setAutoFillBackground(true);
// this->move(50, 50); //移动位置
//输出宽度和高度
qDebug()<<"width = "<<this->width()<<" height = "<<this->height();
//输出坐标点
qDebug()<<"坐标点:"<<this->x()<<","<<this->y();
qDebug()<<this->pos();
/******************************************************************/
btn1 = new QPushButton();
btn1->setParent(this); //设置父控件
btn1->resize(75,30);
btn1->move(0, height()/2);
btn1->setText("开启");
btn2 = new QPushButton("关闭",this);
btn2->move(btn1->width(), height()/2);
btn2->resize(btn1->size());
btn3 = new QPushButton("重新启动",this);
btn3->resize(btn1->size());
btn3->move(btn1->width()+btn2->width(), height()/2);
//连接btn1发射的信号给showMes处理
//connect(btn1, SIGNAL(clicked()), this, SLOT(showMes())); //QT4版本的连接
//disconnect(btn1, SIGNAL(clicked()), this, SLOT(showMes())); //QT4版本的断开
//控件指针
//connect(btn1, &QPushButton::clicked, this, &mywnd::showMes); //QT5版本的连接
//disconnect(btn1, &QPushButton::clicked, this, &MyWnd::showMes); //QT5版本的断开
/*
connect(btn1, &QPushButton::clicked, [&](){ //使用Larmda表达式当做槽函数
btn2->setText("22222");
});
*/
// connect(btn3, &QPushButton::clicked, [&](){ //使用Larmda表达式当做槽函数
// emit signal_1();
// });
connect(btn3, &QPushButton::clicked, [&](){
btn1->setEnabled(true);
});
// connect(this, &mywnd::signal_1, this, &mywnd::say_mes); //将自定义信号连接到自定义槽中
connect(this, &mywnd::signal_1, [&](){ //一个信号可以对应多个槽函数
btn2->setText(btn3->text());
});
//connect(btn3, &QPushButton::clicked, this, &mywnd::say_mes);
connect(btn1, &QPushButton::clicked, this, &mywnd::say_mes);
connect(btn2, &QPushButton::clicked, this, &mywnd::say_t);
}
mywnd::~mywnd()
{
}