练习;
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
speech =new QTextToSpeech(this);
//设置窗口标题
this->setWindowTitle("小草君");
//设置窗体图标
this->setWindowIcon(QIcon("D:\\C++\\23021C++\\1.jpg"));
this->setFixedSize(this->size()); // 设置固定尺寸
//设置标签 自适应大小
ui->logoLab->setScaledContents(true);
//设置logo
ui->logoLab->setPixmap(QPixmap("D:\\C++\\23021C++\\baidu.jpg"));
//设置账户和密码使用图片表示
ui->userNameLab->setScaledContents(true);
ui->pwdLab->setScaledContents(true);
ui->userNameLab->setPixmap(QPixmap(":/icon/userName.jpg"));
ui->pwdLab->setPixmap(QPixmap(":/icon/passwd.jpg"));
//对行编辑器进行设置
ui->userNameEdit->setPlaceholderText("账户/手机/邮箱");
ui->pwdEdit->setEchoMode(QLineEdit::Password); //设置密文模式
ui->pwdEdit->setPlaceholderText("密码"); //设置默认值
//给按钮设置图标
ui->loginBtn->setIcon(QIcon(":/icon/login.png"));
ui->loginBtn->setText("登陆");
ui->cancelBtn->setIcon(QIcon(":/icon/cancel.png"));
}
Widget::~Widget()
{
delete ui;
}
//取消按钮-对应的槽函数
void Widget::on_cancelBtn_clicked()
{
//属性版本完成
QMessageBox box(QMessageBox::Question,"询问","您是否确定要退出登录",
QMessageBox::Yes|QMessageBox::No);
int ret = box.exec();
//对结果进行判断
if(ret==QMessageBox::Yes)
{
this->close();
}else if(ret==QMessageBox::No){
;
}
}
//语音播报
void Widget:: my_slot1()
{
speech->say(ui->loginBtn->text());
}
void Widget::on_loginBtn_clicked()
{
QString userName=ui->userNameEdit->text();
QString pwd=ui->pwdEdit->text();
if(userName=="123456"&&pwd=="123456")
{
//信息对话框
QMessageBox::information(this,"登录信息","登录成功");
qDebug()<<"登录成功";
this->close();
}
else{
QMessageBox::StandardButton btn= QMessageBox::critical(this,
"失败信息",
"账号或密码错误",
QMessageBox::Yes|QMessageBox::No);
//对用点击的结果进行判断
if(btn==QMessageBox::Yes)
{
ui->pwdEdit->clear();
}else if(btn==QMessageBox::No)
{
this->close();
}
qDebug()<<"登陆失败";
ui->pwdEdit->clear();
}
}