QT day2

简单登录界面

mainwindow.cpp


#include "mainwindow.h"
#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //设置主窗口大小
    this->setFixedSize(600,500);
    //设置标题
    this->setWindowTitle("pp");
    //设置图标
    this->setWindowIcon(QIcon(":/res/icon.png"));
    //设置banner
    Banner =new QLabel(this);
    Banner->resize(600,200);
    Banner->setScaledContents(true);
    Banner->setPixmap(QPixmap(":/res/banner.png"));
    //设置用户名图标
    userNamelogo=new QLabel(this);
    userNamelogo->resize(40,40);
    userNamelogo->move(180,250);
    userNamelogo->setScaledContents(true);
    userNamelogo->setPixmap(QPixmap(":/res/man.png"));
    //设置密码图标
    userPwdlogo=new QLabel(this);
    userPwdlogo->resize(40,40);
    userPwdlogo->move(180,325);
    userPwdlogo->setScaledContents(true);
    userPwdlogo->setPixmap(QPixmap(":/res/lock1.png"));
    //设置用户名框
    userName=new QLineEdit(this);
    userName->resize(200,30);
    userName->move(240,255);
    userName->setEchoMode(QLineEdit::Normal);
    userName->setPlaceholderText("用户名");
    //设置密码框
    userPwd=new QLineEdit(this);
    userPwd->resize(200,30);
    userPwd->move(240,330);
    userPwd->setEchoMode(QLineEdit::Password);
    userPwd->setPlaceholderText("密码");
    //设置登录按钮
    button_login=new QPushButton(this);
    button_login->resize(80,30);
    button_login->move(160,420);
    button_login->setText("登录");
    button_login->setIcon(QIcon(":/res/login.png"));
    connect(this->button_login,&QPushButton::clicked,this,&MainWindow::on_login_clicked);
    //设置退出按钮
    button_exit=new QPushButton(this);
    button_exit->resize(80,30);
    button_exit->move(360,420);
    button_exit->setText("退出");
    button_exit->setIcon(QIcon(":/res/exit.png"));
    connect(this->button_exit,&QPushButton::clicked,this,&MainWindow::on_exit_clicked);
}

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

void MainWindow::on_login_clicked()
{
    if(this->userName->text()=="abc"&&this->userPwd->text()=="123"){
        qDebug()<<"登录成功";
        this->close();
    }else{
        this->userPwd->setText("");
        qDebug()<<"登录失败";

    }
}

void MainWindow::on_exit_clicked()
{
    this->close();
}


mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QPushButton>//按钮
#include <qlabel.h>//标签
#include <QLineEdit>///行编辑器


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow

{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    QLabel *Banner;
    QLabel *userNamelogo;
    QLabel *userPwdlogo;
    QPushButton *button_login;
    QPushButton *button_exit;
    QLineEdit *userName;
    QLineEdit *userPwd;
};

#endif // MAINWINDOW_H

现象:

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值