qt仿制qq登录界面

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    //    设置窗口大小
    this->resize(window_width, window_heigth);
    //    固定窗口大小
    this->setFixedSize(window_width, window_heigth);
    //    设置窗口图标
    this->setWindowIcon(QIcon("E:/code/pictrue/qq.png"));
    //    设置窗口背景颜色
    this->setStyleSheet("background-color:rgb(255,255,255)");
    //    设置上半部分样式
    QLabel *up_bg = new QLabel(this);
    up_bg->resize(530,150);//设置label大小
    QMovie *mv_bg = new QMovie("E:\\code\\pictrue\\login-bg.gif");//设置背景图片
    up_bg->setScaledContents(true);//设置图片按比例缩放
    up_bg->setMovie(mv_bg);//把动图添加到label容器中
    mv_bg->start();//让动图动起来
    //    设置中间的头像图片
    QLabel *avater = new QLabel(this);
    avater->setPixmap(QPixmap("E:\\code\\pictrue\\login.png"));
    avater->resize(88,88);
    avater->move(220,100);//移动label到坐标系x220,y100
    avater->setScaledContents(true);
    //    下半部分登录
    //    用户名lable
    QLabel *username_icon = new QLabel(this);
    username_icon->setPixmap(QPixmap("E:\\code\\pictrue\\user-icon.png"));
    username_icon->resize(17,17);
    username_icon->move(115,218);
    username_icon->setScaledContents(true);
//    创建用户名行编辑器
    QLineEdit *user = new QLineEdit(this);
    user->setPlaceholderText("请输入账号");
    user->move(138,208);
    user->resize(296,32);
//    创建密码 lable
    QLabel *paswd_icon = new QLabel(this);
    paswd_icon->setPixmap(QPixmap("E:\\code\\pictrue\\lock-icon.png"));//为label添加图片
    paswd_icon->resize(17,17);
    paswd_icon->move(115,260);
    paswd_icon->setScaledContents(true);
//    创建密码行编辑器
    QLineEdit *paswd = new QLineEdit(this);
    paswd->setPlaceholderText("请输入密码");//设置行编辑器占位符
    paswd->setEchoMode(QLineEdit::Password);//设置显示模式是密码
    paswd->resize(296,32);
    paswd->move(138,254);
//    创建登录按钮
    QPushButton *login_btn = new QPushButton("登录",this);//初始话按钮,按钮文字是登录
    login_btn->resize(296,36);
    login_btn->setStyleSheet("background-color:rgb(7,188,252)");//设置背景颜色
    login_btn->move(130,350);
}

MainWindow::~MainWindow()
{
}

qt仿制qq登录界面_第1张图片

qt仿制qq登录界面_第2张图片 qt初试

你可能感兴趣的:(qt)