QT8.31

创建一个项目,提供三个按钮,第一个按钮实现播报第二个按钮的内容,播报结束后,设置自己不可用。第二个按钮的内容是关闭,实现功能是关掉整个项目,第三个按钮功能是将第一个按钮设置为可以状态

widget.cpp

#include "widget.h"
#include<qdebug.h>
#include<QTextToSpeech>
void Widget::shoeMes()
{
 //   static int i =1;
    this->btn2->setText("鸡");
    speech.say(btn2->text());
    btn1->setEnabled(false);
}

void Widget::say_mes()
{

}
Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(1024,768);
    this->setMaximumSize(500,500);
    this->setFixedSize(800,800);

    this->setWindowTitle("666");
    QString title=this->windowTitle();
 // qDebug()<<title;

    this->setBackgroundRole(QPalette::Dark);
    this->setAutoFillBackground(true);

    qDebug()<<"坐标点"<<this->x()<<","<<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);

    //connect(btn1,SIGNAL(clicked()),this,SLOT(shoeMes()));    //q4
    connect(btn1,&QPushButton::clicked,this,&Widget::shoeMes);  //q5

   // connect(btn1,&QPushButton::clicked,[&](){btn2->setText("2222");}); //使用larmda表达式

     connect(btn3,&QPushButton::clicked,[&](){
         emit singal_1();
     });

     connect(this,&Widget::singal_1,[&]()
     {
        speech.say(btn3->text());
        btn1->setEnabled(true);
     });
 /*    connect(this,&Widget::singal_1,[&](){    //将自定义信号连接到自定义槽
            btn2->setText(btn3->text());
        });
 */
     connect(btn2,&QPushButton::clicked,this,&Widget::close);
}

Widget::~Widget()
{
}

widget.h

#ifndef WIDGET_H
#define WIDGET_H
#include<qpushbutton.h>
#include <QWidget>
#include<QTextToSpeech>
class Widget : public QWidget
{
    Q_OBJECT
signals:
   void singal_1();
public slots:
    void shoeMes();
    void say_mes();
public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    QPushButton *btn1;
    QPushButton *btn2;
    QPushButton *btn3;
    QPushButton *btn4;

    QTextToSpeech speech;
};
#endif // WIDGET_H
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值