QT - 20230707

登录界面练习

#include "loginwindow.h"

QIcon fetchIconWithName(QString name) {
    QString res = "../login/images/" + name;
    return QIcon(res);
}

LoginWindow::LoginWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->resize(600, 800);

    this->setWindowIcon(fetchIconWithName("QQ.png"));
    this->setWindowTitle("登录界面");
    this->setStyleSheet("background-color:white");

    int offsetX = 0, offsetY = 10;

    //LOGO
    QLabel *logoLabel = new QLabel(this);
    logoLabel->setPixmap(QPixmap("../login/images/logo.png"));
    logoLabel->setGeometry((this->width()-480)/2, offsetY, 480, 266);
    offsetY += 266;

    offsetY += 20;

    //登录框
    offsetX = (this->width()-260)/2;
    QLabel *loginIcon = new QLabel(this);
    loginIcon->setPixmap(QPixmap("../login/images/userName.jpg"));
    loginIcon->setScaledContents(true);
    loginIcon->setGeometry(offsetX, offsetY, 50, 50);
    offsetX += (50+10);

    QLineEdit *loginInput = new QLineEdit(this);
    loginInput->setPlaceholderText("请输入用户名");
    loginInput->setGeometry(offsetX, offsetY, 200, 50);
    loginInput->setStyleSheet("border:none");

    QWidget *loginBottomLine = new QWidget(this);
    loginBottomLine->setStyleSheet("background-color:black");
    loginBottomLine->setGeometry(loginInput->x(), loginInput->y()+loginInput->height(), loginInput->width(), 1);
    offsetY += (50+10);

    offsetX = (this->width()-260)/2;
    QLabel *passwdIcon = new QLabel(this);
    passwdIcon->setPixmap(QPixmap("../login/images/passwd.jpg"));
    passwdIcon->setScaledContents(true);
    passwdIcon->setGeometry(offsetX, offsetY, 50, 50);
    offsetX += (50+10);

    QLineEdit *passwdInput = new QLineEdit(this);
    passwdInput->setPlaceholderText("请输入密码");
    passwdInput->setGeometry(offsetX, offsetY, 200, 50);
    passwdInput->setEchoMode(QLineEdit::Password);
    passwdInput->setStyleSheet("border:none");

    QWidget *passwdBottomLine = new QWidget(this);
    passwdBottomLine->setStyleSheet("background-color:black");
    passwdBottomLine->setGeometry(passwdInput->x(), passwdInput->y()+passwdInput->height(), passwdInput->width(), 1);
    offsetY += 60;

    offsetX = (this->width()-150)/2;
    QPushButton *loginBtn = new QPushButton(this);
    loginBtn->setIcon(fetchIconWithName("login.png"));
    loginBtn->setIconSize(QSize(50, 50));
    loginBtn->setGeometry(offsetX, offsetY, 50, 50);
    offsetX += (50 + 20);

    QPushButton *cancelBtn = new QPushButton(this);
    cancelBtn->setIcon(fetchIconWithName("cancel.png"));
    cancelBtn->setIconSize(QSize(50, 50));
    cancelBtn->setGeometry(offsetX, offsetY, 50, 50);
    offsetY += 70;

    this->resize(this->width(), offsetY);

}

LoginWindow::~LoginWindow()
{

}

结果展示:
在这里插入图片描述

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值