QT day2

本文详细描述了如何使用C++和Qt库在Windows应用程序中创建一个具有动态图像、文本输入框及登录验证功能的无边框窗口,包括界面元素的布局和处理用户输入的逻辑。
摘要由CSDN通过智能技术生成

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->resize(645,490);
    this->setFixedSize(645,490);
    this->setStyleSheet("background-color:rgb(255,255,255)");
    this->setWindowFlag(Qt::FramelessWindowHint);

    QLabel *lab1 = new QLabel(this);
    lab1->resize(645,260);
    lab1->setStyleSheet("background-color:blue");

    QMovie *mv = new QMovie("D:\\qq\\pictrue\\qq2.gif");
    mv->setParent(this);
    lab1->setMovie(mv);
    mv->start();
    lab1->setScaledContents(true);

    QLabel *lab2 = new QLabel(this);
    lab2->resize(40,40);
    lab2->move(145,260);
    lab2->setPixmap(QPixmap("D:\\qq\\pictrue\\wodepeizhenshi.png"));
    lab2->setScaledContents(true);

    QLabel *lab3 = new QLabel(this);
    lab3->resize(40,40);
    lab3->move(145,310);
    lab3->setPixmap(QPixmap("D:\\qq\\pictrue\\passwd.jpg"));
    lab3->setScaledContents(true);

//    QLineEdit *edit1 = new QLineEdit(this);
//    edit1->move(195,260);
//    edit1->resize(330,40);
//    edit1->setPlaceholderText("账号/手机号");

//    QLineEdit *edit2 = new QLineEdit(this);
//    edit2->move(195,310);
//    edit2->resize(330,40);
//    edit2->setPlaceholderText("密码");
//    edit2->setEchoMode(QLineEdit::Password);

    ui->edit2->setEchoMode(QLineEdit::Password);

    QPushButton *btn = new QPushButton(this);
    btn->setText("登录");
    btn->resize(380,60);
    btn->move(145,405);
    btn->setStyleSheet("background:rgb(7,188,252);color:white;border-radius:8px");

    QPushButton *btn1 = new QPushButton(this);
    btn1->setText("注册账号");
    btn1->resize(85,25);
    btn1->move(15,435);
    btn1->setStyleSheet("background:rgb(255,255,255);color:rgb(166,166,166)");

    QPushButton *btn2 = new QPushButton(this);
    btn2->setText("取消");
    btn2->move(570,440);
    btn2->resize(60,30);
    btn2->setStyleSheet("background:rgb(255,255,255);color:rgb(166,166,166)");

    connect(btn2,SIGNAL(clicked()),this,SLOT(close()));

    connect(btn, &QPushButton::clicked, this, &Widget::my_slot);
}

void Widget::my_slot()
{
    if(ui->edit1->text()=="admin"&&ui->edit2->text()=="123456")
    {
        qDebug() << "登录成功";
        this->close();
    }
    else
    {
        qDebug() << "登录失败";
        ui->edit1->clear();
        ui->edit2->clear();
    }
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值