QTday2

1.简单的登录界面

//头文件
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTextToSpeech>
#include <QDebug>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT
public slots:
    void my_slot()
    {
        if(this->lin_pwd->echoMode() ==QLineEdit::Password)
        {
            lin_pwd->setEchoMode(QLineEdit::Normal);
            p_pwd->setIcon(QIcon(":/picture/pwd.jfif"));

        }
        else
        {
            lin_pwd->setEchoMode(QLineEdit::Password);
            p_pwd->setIcon(QIcon(":/picture/npwd.jfif"));
        }
    }
    void my_out()
    {
        this->close();
    }

    void my_login()
    {
        if(this->lin_log->text() == "abcabc")
        {
            if(this->lin_pwd->text() =="123456")
            {
                this->close();
            }
            else
            {
                this->lin_pwd->setText("");
            }
        }
        else
        {
            this->lin_pwd->setText("");
        }
    }
    void login_p()
    {
        if(this->lin_log->text() == "")
        {
            p_log->setEnabled(false);
        }
        else
        {
            p_log->setEnabled(true);
        }
    }
    void speek()
    {
        this->s->say(p_cancel->text());
    }
public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    Ui::Widget *ui;
    QLabel *la_backgroud;
    QLabel *la_log;
    QLabel *la_pwd;

    QTextToSpeech *s;

    QPushButton *p_log;
    QPushButton *p_cancel;
    QPushButton *p_pwd;

    QLineEdit *lin_log;
    QLineEdit *lin_pwd;

};
#endif // WIDGET_H

//源文件
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置标题上的
    this->setWindowIcon(QIcon(":/picture/2.png"));
    this->setWindowTitle("PP");
    //背景图片
    s = new QTextToSpeech(this);
    la_log = new QLabel(this);
    la_pwd = new QLabel(this);
    la_backgroud = new QLabel(this);

    lin_log = new QLineEdit(this);
    lin_pwd = new QLineEdit(this);

    p_log = new QPushButton(this);
    p_cancel = new QPushButton(this);
    p_pwd = new QPushButton(this);


    this->setFixedSize(600,450);

    la_backgroud->resize(600,225);
    la_backgroud->setPixmap(QPixmap(":/picture/1.png"));
    la_backgroud->setScaledContents(true);

    la_log->resize(30,30);
    la_log->setPixmap(QPixmap(":/picture/1.jpg"));
    la_log->setScaledContents(true);
    la_log->move(140,275);
    la_pwd->resize(30,30);
    la_pwd->setPixmap(QPixmap(":/picture/th.jfif"));
    la_pwd->setScaledContents(true);
    la_pwd->move(140,325);

    lin_log->resize(280,30);
    lin_log->setPlaceholderText("账号");
    lin_log->move(180,275);

    lin_pwd->resize(280,30);
    lin_pwd->setPlaceholderText("密码");
    lin_pwd->move(180,325);
    lin_pwd->setEchoMode(QLineEdit::Password);

    //p_log->resize(70,30);
    p_log->move(100,400);
    p_log->setText("登录");

    //p_cancel->resize(70,30);
    p_cancel->move(400,400);
    p_cancel->setText("取消");

    p_pwd->setIcon(QIcon(":/picture/npwd.jfif"));
    p_pwd->resize(30,30);
    p_pwd->move(470,325);
    //connect(this->q2,&QPushButton::clicked,this,&Widget::my_slot1);
    connect(this->p_pwd,&QPushButton::clicked,this,&Widget::my_slot);

    //connect(this->p_cancel,&QPushButton::clicked,this,&Widget::my_out);
    connect(this->p_cancel,&QPushButton::clicked,this,&Widget::speek);

    connect(this->p_log,&QPushButton::clicked,this,&Widget::my_login);

    connect(this->lin_log,&QLineEdit::textChanged,this,&Widget::login_p);



}

Widget::~Widget()
{
    delete ui;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值