QT DAY 2

 

 window.cpp

#include "window.h"
#include<QDebug>
#include<QIcon>
Window::Window(QWidget *parent) //构造函数的定义
    : QWidget(parent)           //显性调用父类的构造函数
{
    //
    this->resize(430,330);
    this->resize(QSize(800,600));
    //  this->setMaximumSize(430,330);
     //  this->setMinimumSize(430,330);
    this->setFixedSize(430,330);// 设置尺寸最值
    //窗口标题
    this->setWindowTitle("WeChat");
    //窗口icon
    this->setWindowIcon(QIcon(":/icon/111.png"));
    //设置背景色
    this->setStyleSheet("background-color:skyblue;");
    //设置窗口透明度
    this->setWindowOpacity(1);

    //无参构造
    bt1 =new QPushButton;
    //给组件指定父组件,让其依附于界面
    bt1->setParent(this);
    //设置组件文本内容
    bt1->setText("开始");
    this->setFixedSize(430,330);
    //设置按钮组件的大小
    bt1->resize(QSize(50,30));
   //移动组件位置
    bt1->move(200,290);
    //设置样式表
    bt1->setStyleSheet("background-color:red");
    bt1->setIcon(QIcon("E:\\c\\qt1\\111.png"));
    //2.构造一个按钮
    bt2 = new QPushButton(this);
    bt2->setText("取消");
    bt2->resize(bt1->size());
    bt2->move(300,290);
   // bt2->setStyleSheet("background-color:blue");
   // bt2->setEnabled(false);
    bt2->setIcon(QIcon("E:\\c\\qt1\\111.png"));
    //3.创建图标
    bt3 =new QLabel(this);
    bt3->resize(bt1->size());
    bt3->move(100,170);
    bt3->setPixmap(QString("E:\\c\\qt1\\111.png"));
    //设置 内容自适应
    bt3->setScaledContents(true);
    //4.创建图标
    bt4 =new QLabel(this);
    bt4->resize(bt1->size());
    bt4->move(100,220);
    bt4->setPixmap(QString("E:\\c\\qt1\\222.png"));
    //设置 内容自适应
    bt4->setScaledContents(true);
    /***********************************/
    ed1 =new QLineEdit(this);
    //ed1->setText(""); //设置编辑器中的文本
    //设置占位文本
    ed1->setPlaceholderText("密码:");
    //设置尺寸
    ed1->resize(180,30);
    //移动位置
    ed1->move(bt4->x()+60,bt4->y());
    ed1->setPlaceholderText("密码:");
    ed1->setEchoMode(QLineEdit::Password);
    //2.构造一个行编辑器,构造时给定父,以及文本内容
    ed2 = new QLineEdit(this);
    ed2->resize(180,30);
    ed2->move(bt3->x()+60,bt3->y());
    ed2->setPlaceholderText("账号 /手机 /邮箱...");
     /***********************************/
    la1 =new QLabel(this);
    la1 ->resize(430,140);
    la1->setPixmap(QString("E:\\c\\qt1\\222.png"));
    //设置 内容自适应
    la1->setScaledContents(true);

    connect(this->bt1,&QPushButton::clicked,this,&Window::bt1_clicked);
   //
    connect(this,&Window::my_signal,[&](){
        this->close();
    });
    //使用qt4连接,
    connect(bt2,SIGNAL(clicked()),this,SLOT(close()));


}
Window::~Window()
{
}

void Window::bt1_clicked()
{
    qDebug() << Window::ed2->text();
    qDebug() << Window::ed1->text();
    if(Window::ed2->text()=="473667977")
    {
        if(Window::ed1->text()=="123456")
        {
            qDebug()<<"登录成功";
            emit jump();
            emit my_signal();
        }
        else{
         qDebug()<<"密码错误";
         Window::ed1->setText("");
        }
     }
    else
    {
        qDebug()<<"账号错误";
        Window::ed1->setText("");
        Window::ed2->setText("");
    }
}

 main.cpp

#include "window.h"
#include"form.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Window w;
    w.show();
    Form f;
    QObject::connect(&w,&Window::jump,&f,&Form::jump_slot);
    return a.exec();
}

 form.cpp

#include "form.h"
#include "ui_form.h"

Form::Form(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form)
{
    ui->setupUi(this);
}

Form::~Form()
{
    delete ui;
}
void Form::jump_slot()
{
    this->show();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zycyydssss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值