QT day2

QT day2_第1张图片

QT day2_第2张图片

QT day2_第3张图片

QT day2_第4张图片

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include 
#include 

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
signals:
    void my_signal();
public slots:
    void my_slot();//自定义一个槽函数
    void loginbtn_slot();

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //窗口的相关设置
    this->setWindowTitle("QQ");
    this->setWindowIcon(QIcon(":/pictrue/qq.png"));

    //标签的相关设置
    ui->logolabel->setPixmap(QPixmap(":/pictrue/logo.png"));
    ui->logolabel->setScaledContents(true);

    //账号和密码
    ui->usernamelabel->resize(35,35);
    ui->usernamelabel->setPixmap(QPixmap(":/pictrue/userName.jpg"));
    ui->usernamelabel->setScaledContents(true);

    ui->passwordlabel->resize(35,35);
    ui->passwordlabel->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
    ui->passwordlabel->setScaledContents(true);

    ui->usernamelineEdit->setPlaceholderText("QQ账号/手机号码/邮箱");
   // ui->usernamelineEdit->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
   // ui->usernamelineEdit->adjustSize();
    ui->passwordlineEdit->setEchoMode(QLineEdit::Password);

    //登录按钮和取消登录按钮
    ui->loginbtn->setIcon(QIcon(":/pictrue/login.png"));
    ui->cancelbtn->setIcon(QIcon(":/pictrue/cancel.png"));

    //手动连接信号和槽函数,基于qt4版本 是不友好的连接
    connect(ui->cancelbtn,SIGNAL(clicked()),this,SLOT(my_slot()));

    //qt5版本 判断账号是否为admin,密码是否为123456
    connect(ui->loginbtn,&QPushButton::clicked,this,&MainWindow::loginbtn_slot);


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::my_slot()
{
    this->close();
}

void MainWindow::loginbtn_slot()
{
    if(ui->usernamelineEdit->text()=="admin" && ui->passwordlineEdit->text()=="123456")
    {
        qDebug() << "登录成功";
    }
    else
    {
        qDebug() << "登录失败";
        ui->usernamelineEdit->setText("");
        ui->passwordlineEdit->setText("");
        this->close();
    }

}

你可能感兴趣的:(QT,qt)