头文件
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QDebug>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private slots:void on_Login_clicked();private:Ui::Widget *ui;
};
#endif // WIDGET_H
功能文件
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);//大图ui->Lab->setPixmap(QPixmap(":/pictrue/KT.png"));ui->Lab->setScaledContents(true);//头像ui->Headed->setPixmap(QPixmap(":/pictrue/wodepeizhenshi.png"));ui->Headed->setScaledContents(true);//账号ui->Zhang->setPixmap(QPixmap(":/pictrue/userName.jpg"));ui->Zhang->setScaledContents(true);//密码ui->Mi->setPixmap(QPixmap(":/pictrue/passwd.jpg"));ui->Mi->setScaledContents(true);//按键(确定)connect(ui->Login,&QPushButton::clicked,this,&Widget::on_Login_clicked);//按键(退出)connect(ui->Out,SIGNAL(clicked()),this,SLOT(close()));//密码不可见ui->Password->setEchoMode(QLineEdit::Password);}Widget::~Widget()
{delete ui;
}void Widget::on_Login_clicked()
{if(ui->Username->text()=="admin" && ui->Password->text()=="123456"){qDebug() << "登陆成功";this->close();}else{qDebug() << "登陆失败";ui->Username->clear();ui->Password->clear();}
}
main.cpp文件
#include "widget.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();return a.exec();
}
ui创建版图
Xmind