QTday1代码的形式实现登录框

news/2024/9/29 0:08:01/

代码注释

main.cpp

#include "widget.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);//调用应用程序类的有参构造的实例化对象Widget w;//调用自定义的有参构造实例化的对象w.show();//调用该类的父类里的成员函数show,显示窗口return a.exec();//调用应用程序类实例化对象的成员函数exec,用于阻塞等待刷新事件
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent)//自定义类的有参构造: QWidget(parent), ui(new Ui::Widget)//类中成员指针的堆区空间初始化
{ui->setupUi(this);//拖拽的内容的父组件设置为自定义类的指针,拖拽的内容显示在该类的窗口上
}Widget::~Widget()
{delete ui;//释放堆区空间的指针。
}

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>//ui_widget中的命名空间
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }//ui命名空间的声明
QT_END_NAMESPACEclass Widget : public QWidget//自定义类继承于父类QWidget
{Q_OBJECT//信号与槽的宏,没有该宏,不能使用信号与槽public:Widget(QWidget *parent = nullptr);//带有默认函数的有参/无参构造,形参是指定父组件~Widget();//析构函数,还是虚析构,说明父类的析构也是虚析构,回收指向子类对象的父类指针//时同时回收子类的空间
private:Ui::Widget *ui;//拖拽类的指针
};
#endif // WIDGET_H

登录框

mainwindow.cpp

#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{this->setWindowIcon(QIcon("G://24071//QQ"));this->resize(QSize(360,480));this->setWindowTitle("QQ");QLabel *logo  = new QLabel(this);logo->resize(360,150);logo->setText("QQ");logo->setAlignment(Qt::AlignCenter);logo->setStyleSheet("background-color:lightblue");QLabel *lab1  = new QLabel(this);lab1->resize(30,20);lab1->setText("账号");lab1->move(50,240);QLabel *lab2  = new QLabel(this);lab2->resize(lab1->size());lab2->setText("密码");lab2->move(lab1->x(),lab1->y()+lab1->height()+10);QLineEdit *ledit1 = new QLineEdit(this);ledit1->resize(200,20);ledit1->setAlignment(Qt::AlignCenter);ledit1->setPlaceholderText("输入QQ账号");ledit1->move(lab1->x()+lab1->width()+10,lab1->y());QLineEdit *ledit2 = new QLineEdit(this);ledit2->resize(ledit1->size());ledit2->setAlignment(Qt::AlignCenter);ledit2->setPlaceholderText("输入QQ密码");ledit2->move(ledit1->x(),ledit1->y()+ledit1->height()+10);QPushButton *btn1 = new QPushButton(this);btn1->setText("登录");btn1->resize(50,30);btn1->move(lab1->x()+(lab1->width()+ledit1->width())/2,lab1->y()+ledit1->y()/2);btn1->setStyleSheet("color:white;background-color:lightblue;border-radious:10px;");QPushButton *btn2 = new QPushButton(this);btn2->setText("取消");btn2->resize(50,30);btn2->move(btn1->x()+btn1->width()+20,btn1->y());btn2->setStyleSheet("color:white;background-color:lightblue;border-radious:10px;");}MainWindow::~MainWindow()
{}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QIcon>
#include <QLabel>
#include <QLineEdit>#include <QMainWindow>
#include <QPushButton>class MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();
};
#endif // MAINWINDOW_H

思维导图


http://www.ppmy.cn/news/1531671.html

相关文章

spring6启用Log4j2日志

pom文件 <!--log4j2的依赖--> <dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>2.23.1</version> </dependency> <dependency><groupId>org.apache…

C++入门编程题(力扣):字符串中最多数目的子序列

1.题目描述&#xff1a; 给你一个下标从0开始的字符串 text 和另一个下标从0开始且长度为 2 的字符串 pattern两者都只包含小写英文字母。 你可以在 text 中任意位置插入 一个 字符&#xff0c;这个插入的字符必须是 pattern[0]或者 pattern[1]。 注意&#xff0c;这个字符可以…

Spring Boot 基础入门指南

1. 什么是 Spring Boot&#xff1f; Spring Boot 是一个用于简化 Spring 应用程序开发的框架&#xff0c;旨在让开发者快速构建独立的、生产级的 Spring 应用。它提供了自动配置、嵌入式服务器和一系列开箱即用的功能&#xff0c;降低了应用程序的开发和部署难度。 2. Spring…

青动CRM V3.2.1

全面解决企业销售团队的全流程客户服务难题旨在助力企业销售全流程精细化、数字化管理&#xff0c;全面解决企业销售团队的全流程客户服务难题&#xff0c;帮助企业有效盘活客户资源、量化销售行为&#xff0c;合理配置资源、建立科学销售体系&#xff0c;提升销售业绩。标准授…

Spring MVC常用注解(绝对经典)

文章目录 一、元注解1.1 Target&#xff1a;1.2 Retention&#xff1a; 二、常见注解2.1 Controller&#xff1a;2.2 SpringBootApplication&#xff1a;2.3 RequestMapping&#xff1a;2.4 RequestParam&#xff1a;2.5 PathVariable&#xff1a;2.6 RequestPart&#xff1a;2…

【数据库】sqlite

文章目录 1. 基本概述2. 主要特点3. 应用场景4. 优缺点5. 基本使用示例6. 在编程语言中的使用连接到 SQLite 数据库&#xff08;如果文件不存在会自动创建&#xff09;创建表插入数据提交事务查询数据关闭连接 7. 总结 SQLite 是一个轻量级的关系型数据库管理系统&#xff08;R…

py-mmcif 包entity_poly 对象介绍

在 py-mmcif 包中,entity_poly 对象和 pdbx_poly_seq_scheme 对象都与生物大分子(如蛋白质和核酸)的序列和结构信息相关,但它们的目的和包含的信息有所不同。以下是它们之间的区别和联系: 1. 对象定义与结构 entity_poly 对象: 用于描述生物大分子的聚合体(如多肽或核酸…

Netty--第三章

Netty 进阶 1. 粘包与半包 1.1 粘包现象 服务端代码 public class HelloWorldServer { static final Logger log LoggerFactory.getLogger(HelloWorldServer.class); void start() { NioEventLoopGroup boss new NioEventLoopGroup(1); NioEventLoopGroup worker new Nio…