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()
{

}

结果展示:
QT - 20230707_第1张图片

QT - 20230707_第2张图片

你可能感兴趣的:(qt)