头文件
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
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