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

窗口实现代码

cpp 复制代码
#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()
{

}

效果图

相关推荐
fl1768315 小时前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf
weixin_440730505 小时前
python+request实现接口-小结
开发语言·python
ZJU_统一阿萨姆6 小时前
【算子开发】扫描(Scan)与前缀和
开发语言·arm开发·架构·系统架构·硬件架构
zlinear数据采集卡6 小时前
数据采集卡从入门到精通(38):上位机开发实战——Python/QT/LabVIEW的技术选型与分层架构
python·单片机·嵌入式硬件·qt·fpga开发·开源·labview
-凌凌漆-6 小时前
【C语言】结构体typedef struct与struct的区别
c语言·开发语言
for_ever_love__6 小时前
PySpark学习: 数据输出
开发语言·python·学习·spark
言乐66 小时前
Python实现自动拉人脚本示例
开发语言·windows·python·django·pygame
啊啊啊啊啊!!!!6 小时前
【c++】二叉搜索树
开发语言·c++
归去来 兮7 小时前
Python爬虫爬取数据案例
开发语言·爬虫·python
ShineWinsu7 小时前
对于 C++:C++20中Concept(概念) 与 Coroutine(协程)的解析
linux·开发语言·网络·c++·c++20·epoll