嵌入式学习Day39(Qt)

Qt创建登录界面

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置固定尺寸
    this->setFixedSize(555,375);
    //设置窗口标题
    this->setWindowTitle("QQ");
    //设置窗口图标
    this->setWindowIcon(QIcon(":/new/prefix1/icon/logo.png"));
    //设置背景色
    this->setBackgroundRole(QPalette::Light);
    //设置允许填充背景
    this->setAutoFillBackground(true);

    //定义一个标签,做上半背景
    QLabel *lab_bgp = new QLabel(this);
    //设置尺寸
    lab_bgp->resize(555,150);
    //设置透明度
    lab_bgp->setWindowOpacity(0.3);
    //设置按钮颜色
    lab_bgp->setStyleSheet("background-color:rgb(137,207,240)");

    //定义一个标签头像
    QLabel *lab_hp = new QLabel(this);
    //设置尺寸
    lab_hp->resize(80,80);
    //设置头像图标
    lab_hp->setPixmap(QPixmap("E:\\c++\\qq1.png"));
    lab_hp->move(225,78);
    //设置填充格式:true-自适应大小
    lab_hp->setScaledContents(true);

    //定义一个账号标签
    QLabel *lab_user = new QLabel("账户:",this);
    //设置尺寸
    lab_user->resize(19,23);
    //设置头像图标
    lab_user->setPixmap(QPixmap(":/new/prefix1/icon/userName.jpg"));
    lab_user->move(120,185);
    //设置填充格式:true-自适应大小
    lab_user->setScaledContents(true);

    //定义一个密码标签
    QLabel *lab_pwd = new QLabel("密码:",this);
    //设置尺寸
    lab_pwd->resize(19,22);
    //设置头像图标
    lab_pwd->setPixmap(QPixmap(":/new/prefix1/icon/passwd.jpg"));
    lab_pwd->move(120,240);
    //设置填充格式:true-自适应大小
    lab_pwd->setScaledContents(true);

    //定义账号的行编辑
    QLineEdit *edt_user = new QLineEdit(this);
    //设置尺寸和位置
    edt_user->resize(280,45);
    edt_user->move(140,170);
    //设置默认值
    edt_user->setPlaceholderText("账户");
    //设置边框只留底行
    edt_user->setStyleSheet("border: none; border-bottom: 1px solid black;");

    //定义密码的行编辑
    QLineEdit *edt_pwd = new QLineEdit(this);
    //设置尺寸和位置
    edt_pwd->resize(280,45);
    edt_pwd->move(140,230);
    //设置默认值
    edt_pwd->setPlaceholderText("密码");
    //设置密码行为回显模式
    edt_pwd->setEchoMode(QLineEdit::Password); //设置密文模式
    //设置边框只留底行
    edt_pwd->setStyleSheet("border: none; border-bottom: 1px solid black;");

    //定义登录按钮
    QPushButton *btn_login = new QPushButton("登录",this);
    //设置登录图片
    btn_login->setIcon(QIcon(":/new/prefix1/icon/login.png"));
    //设置尺寸、位置和颜色
    btn_login->resize(80,40);
    btn_login->move(150,300);
    btn_login->setStyleSheet("background-color:rgb(19,183,246)");
    //将登录按钮发射的信号手动连接到lambda表达式中
    connect(btn_login,&QPushButton::clicked,[=]()
            {
                if(edt_user->text() == nullptr)
                    qDebug() << "请输入账号";
                else if(edt_pwd->text() == nullptr)
                    qDebug() << "请输入密码";
                else{
                    if(edt_user->text() == "admin" && edt_pwd->text() == "123456")
                        qDebug() << "登录成功";
                    else{
                        qDebug() << "密码错误";
                        edt_pwd->clear();
                   }
                }
            }
    );

    //定义登录按钮
    QPushButton *btn_cancel = new QPushButton("取消",this);
    //设置取消图片
    btn_cancel->setIcon(QIcon(":/new/prefix1/icon/cancel.png"));
    //设置尺寸、位置和颜色
    btn_cancel->resize(80,40);
    btn_cancel->move(310,300);
    btn_cancel->setStyleSheet("background-color:red");
    //将取消按钮发射的信号手动连接到lambda表达式中
    connect(btn_cancel,&QPushButton::clicked,  [&]()
            {
                close();
            }
    );
}
Widget::~Widget()
{
    delete ui;
}

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值