• 初见QT,控件的基本应用,实现简单登录窗口


    窗口实现代码

    #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()
    {
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61

    效果图

    在这里插入图片描述

  • 相关阅读:
    【大数据】Apache NiFi 助力数据处理及分发
    mongodump工具安装及使用详解
    http 302状态码
    【SpringBoot系列教程-目录大纲】
    【数据科学赛】2023年亚太眼科学会大数据竞赛 #$15000 #阿里天池 #分类
    [YOLOV7] Win10+Anaconda+Pytorch 部署YOLOv7(含踩坑解决方案)
    整形和浮点型是如何在内存中的存储
    Linux常用指令(十一)——关机重启
    Spring @Transactional 原理解析
    Spring常见问题解决 - 自定义ApplicationEnvironmentPreparedEvent监听器失效了?
  • 原文地址:https://blog.csdn.net/m0_72847002/article/details/132910643