Qt --- Day01

效果图:

头像的圆形未实现

Qt --- Day01_第1张图片

单击登陆,触发信号与槽

Qt --- Day01_第2张图片

enter_widget.h

#ifndef ENTER_H
#define ENTER_H

#include 
#include
#include
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的头文件
#include   //信息调试类,用于输出数据使用
#include
#include
#include
#include
#include
#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()<size();   //获取当前姐买你的尺寸
    qDebug()<width();  //获取当前组件的宽度
    qDebug()<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 

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

你可能感兴趣的:(Qt,qt,开发语言)