思维导图
2>
完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示”登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面
如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面
如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes|No,用户点击Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
要求:(基于属性版、静态成员函数都使用)实现对话框的弹出
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
ui->setupUi(this);
//去掉头部
this->setWindowFlag(Qt::FramelessWindowHint);
//去掉空白部分
this->setAttribute(Qt::WA_TranslucentBackground);
//自动链接不行,就换用自动链接(就是将自动跳转的槽函数给名字稍微改一下,变成自定义的槽函数,再在这里手动调用)
connect(ui->pushButton,&QPushButton::clicked, this, &Widget::pushButton_clicked);
connect(ui->cha,&QPushButton::clicked, this,&Widget::cha_clicked);
connect(ui->max,&QPushButton::clicked, this,&Widget::max_clicked);
connect(ui->min,&QPushButton::clicked, this,&Widget::min_clicked);
}
Widget::~Widget()
{
delete ui;
}
void Widget::pushButton_clicked() //登录按钮对应的槽函数
{
qDebug()<<".............";
QString zhanghao = ui->lineEdit->text();//定义账号输入的字符串为zhanghao
QString mima = ui->lineEdit_2->text();//
if(zhanghao == "admin" && mima == "123456")//判断账号密码的正确性
{
QMessageBox msg(QMessageBox::Information,"信息","登陆成功",QMessageBox::Yes,this);
msg.exec();
this->close();//若都正确,则退出窗口
emit my_jump();//触发信号
}
else
{
QMessageBox msg(QMessageBox::Information,"信息","账号和密码不匹配,是否重新登录",QMessageBox::Yes | QMessageBox::No,this);
int ret=msg.exec();
if(ret==QMessageBox::Yes)
{
ui->lineEdit_2->clear();//清除密码框内容
}
else
{
this->close();
}
}
}
void Widget::cha_clicked()//关闭按钮的槽函数
{
qDebug()<<"关闭";
QMessageBox msg(QMessageBox::Information,"信息","您是否确定要退出登录?",QMessageBox::Yes | QMessageBox::No,this);
int ret=msg.exec();
if(ret==QMessageBox::Yes)
{
this->close();
}
else
{
}
}
void Widget::max_clicked()//最大化按钮的槽函数
{
qDebug()<<"最大化";
this->showMaximized();
}
void Widget::min_clicked()//最小化按钮的槽函数
{
qDebug()<<"最小化";
this->showMinimized();
}
使用定时器事件 实现闹钟
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//给语言播报者实例化空间
speecher = new QTextToSpeech(this);
//connect(ui->startBtn,&QPushButton::clicked,speecher,&Widget::my_slots);
}
Widget::~Widget()
{
delete ui;
}
//重写定时器的槽函数
void Widget::timerEvent(QTimerEvent *e)
{
//判断哪一个定时器超时
if(e->timerId() == id)
{
//获取系统时间 QTime
QTime sys_time = QTime::currentTime();
QString t = sys_time.toString("hh--mm--ss");
//将系统时间放到xtTIme
ui->xtTime->setText(t);
//居中显示
ui->xtTime->setAlignment(Qt::AlignCenter);
}
QString t;
if(t == ui->lineEdit->text())
{
ui->naozhong->setText("好好学习 天天向上");
}
}
void Widget::my_slots()//循环播报闹钟
{
if(ui->xtTime->text() == ui->setLab->text())
{
for(int i=0;i<5;i++)
{
speecher->say(ui->naozhong->text());
}
}
else
{
}
}
//启动按钮的槽函数
void Widget::on_startBtn_clicked()
{
if(ui->startBtn->text() == "启动")
{
//启动一个定时器
id=startTimer(1000);
ui->startBtn->setText("关闭");
}
else
{
killTimer(id);
ui->startBtn->setText("启动");
}
}