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

Qt --- Day01

效果图:

头像的圆形未实现

单击登陆,触发信号与槽

enter_widget.h

#ifndef ENTER_H
#define ENTER_H#include <QDialog>
#include<QLabel>
#include<QTimer>
class enter_widget : public QDialog
{Q_OBJECT
public:explicit enter_widget(QDialog *parent = nullptr);
private:QLabel *label;QTimer * time;signals:};#endif // ENTER_H

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>  //基类QWidget的头文件
#include<QDebug>   //信息调试类,用于输出数据使用
#include<QIcon>
#include<QPushButton>
#include<QLabel>
#include<QLineEdit>
#include<QPixmap>
#include"enter_widget.h"
class Widget : public QWidget
{Q_OBJECT   //QT的信号与槽元对象public:Widget(QWidget *parent = nullptr);//默认参数构造函数声明~Widget();//虚析构声明
private:QLabel *pic;QLabel *tx;QPushButton* enter;QPushButton* login;QLabel* user;QLabel* passwd;QLineEdit* user_l;QLineEdit* passwd_l;enter_widget* en;
};
#endif // WIDGET_H

enter_widget.cpp

#include "enter_widget.h"enter_widget::enter_widget(QDialog *parent) : QDialog(parent)
{this->setWindowFlag(Qt::FramelessWindowHint);this->setFixedSize(200,50);this->setStyleSheet("border:1 solid black");label = new QLabel(this);label->resize(200,50);label->setText("登录成功");label->setAlignment(Qt::AlignCenter);label->setStyleSheet("border:0px solid black");time = new QTimer(this);time->start(3000);connect(time,&QTimer::timeout,this,&QDialog::close);
}

widget.cpp

#include "widget.h"Widget::Widget(QWidget *parent): QWidget(parent)
{qDebug()<<this->size();   //获取当前姐买你的尺寸qDebug()<<this->width();  //获取当前组件的宽度qDebug()<<this->height(); //获取当前组件的高度this->setWindowTitle("QQ");//this->resize(500,400);//重新设置界面大小//this->resize(QSize(1000,1000));this->setFixedSize(500,400);//设置固定的界面大小//this->setMaximumSize(600,700);//最大界面大小//this->setMinimumSize(200,300);//最小界面大小this->setWindowIcon(QIcon("C:\\Users\\12609\\Downloads\\qq.png"));pic = new QLabel(this);pic->resize(this->width(),130);pic->setPixmap(QPixmap("E:\\C++\\qt\\fm.png"));pic->setScaledContents(true);tx = new QLabel(this);tx->resize(100,100);tx->move(200,60);tx->setPixmap(QPixmap("E:\\C++\\qt\\2.jpg"));tx->setScaledContents(true);enter = new QPushButton;enter->setParent(this);enter->setText("登录");enter->resize(100,50);enter->move(120,300);enter->setIcon(QIcon("C:\\Users\\12609\\Downloads\\enter.png"));enter->setStyleSheet("border:0px solid black;border-radius:10;background-color:#FFFFFF");login = new QPushButton;login->setParent(this);login->setText("注册");login->resize(100,50);login->move(280,300);login->setIcon(QIcon("C:\\Users\\12609\\Downloads\\enter.png"));login->setStyleSheet("border:0px solid black;border-radius:10;background-color:#FFFFFF");user = new QLabel;user->setParent(this);user->setText("用户名:");user->resize(60,30);user->setAlignment(Qt::AlignCenter);//user->setFixedSize(50,20);user->move(enter->x(),enter->y()-120);passwd = new QLabel(this);passwd->setText("密 码:");passwd->resize(60,30);passwd->setAlignment(Qt::AlignCenter);//user->setFixedSize(50,20);passwd->move(enter->x(),enter->y()-60);user_l = new QLineEdit(this);user_l->resize(200,30);user_l->move(user->x()+60,user->y());user_l->setPlaceholderText("请输入用户名");user_l->setStyleSheet("border:0px solid black;border-radius:10;background-color:#bfbfbf");passwd_l= new QLineEdit(this);passwd_l->resize(200,30);passwd_l->move(passwd->x()+60,passwd->y());passwd_l->setPlaceholderText("请输入密码");passwd_l->setEchoMode(QLineEdit::Password);passwd_l->setStyleSheet("border:0px solid black;border-radius:10;background-color:#bfbfbf");//切换界面en = new enter_widget;connect(enter,&QPushButton::clicked,en,&enter_widget::exec);
}
Widget::~Widget()
{
}

main.cpp

#include "widget.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);//实例化一个应用程序类对象Widget w;//实例化一个自定义的图形化界面类对象w.show();//由基类提供用于展示自己的组件和子组件return a.exec();//阻塞等待用户操作、信号与槽等事件发生
}

http://www.lryc.cn/news/167177.html

相关文章:

  • 24.98万起,新一代AITO问界M7值得买吗?
  • Java毕业设计 SSM SpringBoot 水果蔬菜商城
  • 前端JS中的异步编程与Promise
  • Pytorch Advanced(二) Variational Auto-Encoder
  • Flask 使用 JWT(三)flask-jwt-extended
  • 堆与栈的区别
  • OpenWrt kernel install分析(2)
  • 【计算机网络】传输层协议——TCP(下)
  • Vue前端页面打印
  • Visual Studio将C#项目编译成EXE可执行程序
  • git把某一次commit修改过的文件打包导出(git)
  • Vue3 Ajax(axios)异步
  • idea2023全量方法debug
  • Docker镜像解析获取Dockerfile文件
  • 使用maven命令打jar包
  • 【多线程】死锁 详解
  • 成考[专升本政治]科目必背知识点
  • spring boot 使用AOP+自定义注解+反射实现操作日志记录修改前数据和修改后对比数据,并保存至日志表
  • 【深度学习】Pytorch 系列教程(二):PyTorch数据结构:1、Tensor(张量): GPU加速(GPU Acceleration)
  • 多线程|多进程|高并发网络编程
  • 云计算——ACA学习 云计算分类
  • 3 分钟,带你了解低代码开发
  • 小白学Unity03-太空漫游游戏脚本,控制飞船移动旋转
  • 接口自动化测试推荐用什么框架?
  • 防火墙 FireWall
  • 【Linix-Day12-线程同步和线程安全】
  • C++中使用嵌套循环遍历多维数组
  • linux入门---命名管道
  • SpringBoot2.0入门(详细文档)
  • Aztec的隐私抽象:在尊重EVM合约开发习惯的情况下实现智能合约隐私