嵌入式:QT Day1

一、手动实现登录框

源码:

widge.h

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QDebug>           //用于打印输出
#include <QIcon>            //图标头文件
#include <QPushButton>      //按钮类头文件
#include <QLineEdit>        //行编辑器类
#include <QLabel>           //标签文件

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    //标签类
    QLabel *lab1;
    QLabel *lab2;
    QLabel *lab3;

    //行编辑器类
    QLineEdit *edit1;
    QLineEdit *edit2;

    //按钮类
    QPushButton *btn1;
    QPushButton *btn2;

};
#endif // WIDGET_H

widge.cpp

cpp 复制代码
#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //设置整体大小、标题及图标
    this->setFixedSize(700, 600);
    this->setWindowTitle("IKUN真爱小屋❤");
    this->setWindowIcon(QIcon("F:\\23051C++QT\\QT Day1\\test\\1.jpeg"));
    this->setWindowOpacity(0.95);              //设置透明度

    //设置Logo标签
    lab1 = new QLabel(this);
    lab1->resize(700,200);
    lab1->setPixmap(QPixmap("F:\\23051C++QT\\QT Day1\\test\\2.JPG"));
    lab1->setScaledContents(true);         //设置内容自适应

    //设置用户和密码所图标
    lab2 = new QLabel(this);
    lab2->resize(50,50);
    lab2->setPixmap(QPixmap("F:\\23051C++QT\\QT Day1\\test\\username.png"));
    lab2->setScaledContents(true);
    lab2->move(150,260);

    lab3 = new QLabel(this);
    lab3->resize(50,50);
    lab3->setPixmap(QPixmap("F:\\23051C++QT\\QT Day1\\test\\passwd.jpg"));
    lab3->setScaledContents(true);
    lab3->move(150,360);

    //设置行编辑器
    edit1 = new QLineEdit(this);
    edit1->resize(190, 40);
    edit1->move(280, 265);
    edit1->setStyleSheet("border : none; "
                         "border-bottom: 2px solid grey;");
    edit1->setPlaceholderText("账号:");

    edit2 = new QLineEdit(this);
    edit2->resize(190, 40);
    edit2->move(280, 365);
    edit2->setStyleSheet("border : none; "
                         "border-bottom: 2px solid grey;");
    edit2->setPlaceholderText("密码:");
    edit2->setEchoMode(QLineEdit::Password);

    //设置按钮
    btn1 = new QPushButton(this);
    btn1->setText("登录");
    btn1->resize(130,40);
    btn1->move(150, 490);
    btn1->setIcon(QIcon("F:\\23051C++QT\\QT Day1\\test\\login.png"));

    btn2 = new QPushButton(this);
    btn2->setText("取消");
    btn2->resize(130,40);
    btn2->move(440, 490);
    btn2->setIcon(QIcon("F:\\23051C++QT\\QT Day1\\test\\cancel.png"));
}

Widget::~Widget()
{
}

main.cpp

cpp 复制代码
#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}

二、思维导图:

相关推荐
ん贤2 小时前
Go channel 深入解析
开发语言·后端·golang
2301_789015623 小时前
DS进阶:AVL树
开发语言·数据结构·c++·算法
Filotimo_5 小时前
5.3 Internet基础知识
开发语言·php
识君啊5 小时前
Java异常处理:中小厂面试通关指南
java·开发语言·面试·异常处理·exception·中小厂
qyzm7 小时前
天梯赛练习(3月13日)
开发语言·数据结构·python·算法·贪心算法
leluckys7 小时前
swift- Swift中常见的面试题
开发语言·汇编·swift
BUG_MeDe7 小时前
json格式字符串解析的简单使用 libjson-c
c语言·开发语言·json
CoderCodingNo8 小时前
【GESP】C++五级练习题 luogu-P1182 数列分段 Section II
开发语言·c++·算法