First meeting with QT, basic application of controls, realizing simple login window

Window implementation code

#include "widget.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    
    
    //窗口设置
    this->setFixedSize(538, 373);                                   //固定窗口大小
    this->setWindowIcon(QIcon("G:\\QT_Icon\\windos_icon2.png"));    //设置窗口图标
    this->setWindowTitle("My QQ");                                  //设置窗口标题

    //窗口界面
    QLabel *lab1 = new QLabel(this);                                //设置背景颜色
    QLabel *lab2 = new QLabel(this);                                //设置头像
    lab1->resize(538, 153);                                         //背景颜色范围
    lab1->setStyleSheet("background-color:skyblue");                //设置背景颜色样式

    lab2->setPixmap(QPixmap("G:\\QT_Icon\\windos_icon2.png"));      //设置头像图标
    lab2->resize(80, 80);                                           //设置头像大小
    lab2->setScaledContents(true);                                  //头像自适应填满
    lab2->move(229, 53);                                            //设置头像位置

    //输入框
    QLineEdit *ledit1 = new QLineEdit(this);                        //账号输入
    QLineEdit *ledit2 = new QLineEdit(this);                        //密码输入
    ledit1->resize(260, 40);
    ledit2->resize(260, 40);

    ledit1->move(159, lab2->y()+120);                               //设置账号框位置
    ledit2->move(ledit1->x(), ledit1->y()+60);                      //设置密码框位置

    ledit1->setPlaceholderText("QQ账号/手机号/邮箱");                  //设置占位文本
    ledit2->setEchoMode(QLineEdit::Password);                        //设置密码回显
    ledit1->setMaxLength(16);
    ledit2->setMaxLength(16);

    //输入栏前置图标
    QLabel *lab3 = new QLabel(this);
    QLabel *lab4 = new QLabel(this);
    lab3->resize(30, 30);
    lab3->setPixmap(QPixmap("G:\\QT_Icon\\windos_icon1.png"));
    lab3->setScaledContents(true);
    lab3->move(ledit1->x()-40, ledit1->y()+5);

    lab4->setPixmap(QPixmap("G:\\QT_Icon\\password.png"));
    lab4->setScaledContents(true);
    lab4->resize(30, 30);
    lab4->move(ledit2->x()-40, ledit2->y()+5);

    //按键
    QPushButton *btn1 = new QPushButton("登录" ,this);
    btn1->resize(300, 40);
    btn1->setStyleSheet("background-color:rgb(8,189,253);");
    btn1->move(lab3->x(), lab4->y()+60);

}

Widget::~Widget()
{
    
    

}

renderings

Insert image description here

Guess you like

Origin blog.csdn.net/m0_72847002/article/details/132910643