当前位置: 首页 > article >正文

QT界面制作

作业

1> 创建一个新项目,将默认提供的程序都注释上意义

pro文件
QT       += core gui
#引入类库 core,gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#超过版本4会加上widgets

CONFIG += c++11 
#支持c++11新特性

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

#源文件管理
SOURCES += \
    main.cpp \
    logon.cpp

#头文件管理
HEADERS += \
    logon.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
 .h文件
#ifndef LOGON_H
#define LOGON_H
//防止头文件重复包含
#include <QWidget>

//自定义类,公共继承QWidget:QWidget
class Logon : public QWidget
{
    Q_OBJECT

public:
    Logon(QWidget *parent = nullptr); //构造函数的声明,默认参数
    ~Logon();//继承的虚析构函数
};
#endif // LOGON_H
 源文件
#include "logon.h"

//构造函数定义
Logon::Logon(QWidget *parent)
    : QWidget(parent)
{
}
//析构函数定义
Logon::~Logon()
{
}

主程序 
#include "logon.h"
//头文件包含
#include <QApplication>
//应用程序头文件
int main(int argc, char *argv[])
{
    QApplication a(argc, argv); //实例化对象,调用有参构造
    Logon w;  //自定义类调用无参构造构造界面
    w.show();  //调用展示函数
    return a.exec();//轮询等待界面指令
}

2> 使用代码的形式实现登录框

头文件
#ifndef LOGON_H
#define LOGON_H
//防止头文件重复包含
#include <QWidget>
#include <QPushButton>
#include<QLineEdit>
#include<QLabel>
#include <QMovie>
//自定义类,公共继承QWidget:QWidget
class Logon : public QWidget
{
    Q_OBJECT

public:
    Logon(QWidget *parent = nullptr); //构造函数的声明,默认参数
    ~Logon();//继承的虚析构函数
};
#endif // LOGON_H
源文件 
#include "logon.h"


//构造函数定义
Logon::Logon(QWidget *parent)
    : QWidget(parent)
{

    this->setWindowTitle("QQ");
    this->setWindowIcon(QIcon("D:/shixun/Qt/icon_QQ.png"));
    this->setFixedSize(375,667);

    QPushButton *btn1 = new QPushButton("登录",this);
    btn1->resize(80,40);
    btn1->move(147,450);
    btn1->setStyleSheet("color:white;background-color:rgba(135,206,235,0.5);border-radius:10px");


    QLineEdit *edit1 = new QLineEdit;
    edit1->setParent(this);
    edit1->resize(200,30);
    edit1->move(87,380);
    edit1->setAlignment(Qt::AlignCenter);
    edit1->setPlaceholderText("输入密码");
    edit1->setStyleSheet("background-color:rgba(255,255,255,0.5)");
    edit1->setEchoMode(QLineEdit::Password);

    QLineEdit *edit2 = new QLineEdit;
    edit2->setParent(this);
    edit2->resize(200,30);
    edit2->move(edit1->x(),330);
    edit2->setAlignment(Qt::AlignCenter);
    edit2->setPlaceholderText("输入账号");
    edit2->setStyleSheet("background-color:rgba(255,255,255,0.5)");

    QLabel *lab1 = new QLabel(this);
    lab1->resize(375,667);
    lab1->setPixmap(QPixmap("D:\\shixun\\Qt\\background.jpg"));
    lab1->setScaledContents(true);

    QLabel *lab2 = new QLabel(this);
    lab2->resize(120,90);
    lab2->move(127,220);
    QMovie *movie = new QMovie("D:/XH/bs.gif");
    lab2->setMovie(movie);
    movie->start();
    lab2->setScaledContents(true);

    lab1->lower();

}
//析构函数定义
Logon::~Logon()
{
}

 主程序

#include "logon.h"
//头文件包含
#include <QApplication>
//应用程序头文件
int main(int argc, char *argv[])
{
    QApplication a(argc, argv); //实例化对象,调用有参构造
    Logon w;  //自定义类调用无参构造构造界面
    w.show();  //调用展示函数
    return a.exec();//轮询等待界面指令
}

思维导图


http://www.kler.cn/news/326956.html

相关文章:

  • 粉丝们得以一窥索菲亚罗兰奢华的90岁生日庆祝仪式! 她已完成了所有的遗愿清单 !
  • 选择租用徐州存储服务器有什么作用?
  • 大数据-149 Apache Druid 基本介绍 技术特点 应用场景
  • 2024年7月大众点评广州美食店铺基础信息
  • 2024.9.24 作业
  • Stable Diffusion 蒙版:填充、原图、潜空间噪声(潜变量噪声)、潜空间数值零(潜变量数值零)
  • 我店生活系统小程序开发功能解析
  • uniapp框架中实现文件选择上传组件,可以选择图片、视频等任意文件并上传到当前绑定的服务空间
  • 修改 idea 的 Terminal 命令窗口使用 git-bash
  • 得物App荣获新奖项,科技创新助力高质量发展
  • 国内ChatGPT镜像网站整理汇总【OpenAI o1/GPT 4o】-2024/10月最新
  • 【数据结构与算法】算法和算法分析
  • nginx服务介绍
  • ros2 colcon build 构建后,install中的local_setup.bash 和setup.bash有什么区别
  • 企业数据可视化大屏的工具选择有哪些
  • UI设计师面试整理-设计趋势和行业理解
  • 互斥量mutex、锁、条件变量和信号量相关原语(函数)----很全
  • 从两个 Excel 表格中提取相关信息,并根据学生的 学号 和 姓名 将第一个表格中的成绩数据填充到第二个表格中(附Python代码)
  • 【LeetCode HOT 100】详细题解之链表篇
  • 【Kubernetes】常见面试题汇总(四十八)
  • MySQL实现跨服务器查询
  • Vscode超好看的渐变主题插件
  • Axure9破解
  • MySQL中的嵌套查询
  • Go实现RabbitMQ消息模式
  • 科研绘图系列:R语言堆积图(stacked barplot)
  • 数据驱动农业——农业中的大数据
  • MySQL | excel数据输出insert语句
  • STM8S003F定时器延时
  • 【华为HCIP实战课程二】OSPF基础介绍和OSPF RID NBMA配置详解