![](https://i-blog.csdnimg.cn/direct/cb601c972f654c58a882f2c6e1282451.png)
mywidget::mywidget(QWidget *parent)
: QMainWindow(parent)
{
/*---------------------窗口设置(无边框)----------------------*/
this->setWindowFlag(Qt::FramelessWindowHint);
//窗口大小
this->resize(590,950);
//背景颜色
this->setStyleSheet("background-color:rgb(32,32,32)");
/*----------------------标签设置---------------------------*/
//创建登录标签
QLabel *lab1 = new QLabel(this);
lab1->setText("登录");
//设置大小
lab1->resize(80,40);
//设置字体颜色
lab1->setStyleSheet("color:white;");
lab1->move(255,180);
//设置字体大小
QFont font;
font.setPointSize(12);
//将字体应用于标签
lab1->setFont(font);
//创建图标标签
QLabel *lab2 = new QLabel(this);
//插入图片
lab2->setPixmap(QPixmap(":/1.png"));
//设置标签大小及位置
lab2->resize(100,100);
lab2->move(225,80);
//将图片设置为自适应
lab2->setScaledContents(true);
//设置底部标签
QLabel *lab3 = new QLabel(this);
lab3->setPixmap(QPixmap(":/epic1.png"));
lab3->resize(590,360);
lab3->setScaledContents(true);
lab3->move(0,600);
//登录框(文本框)
/*-----------------------行编辑器相关设置---------------------------------*/
//账号
QLineEdit *edit1 = new QLineEdit(this);
edit1->move(70,240);
edit1->resize(450,80);
edit1->setPlaceholderText("电子邮箱地址");
//设置字体颜色
edit1->setStyleSheet("color:white;");
//设置字体大小
edit1->setFont(font);
//密码
QLineEdit *edit2 = new QLineEdit(this);
edit2->move(70,350);
edit2->resize(450,80);
edit2->setPlaceholderText("密码");
//密码设置为不显示
edit2->setEchoMode(QLineEdit::Password);
//设置字体颜色
edit2->setStyleSheet("color:white;");
//设置字体大小
edit2->setFont(font);
/*------------------------按钮设置------------------------*/
//登录按钮
QPushButton *btn1 = new QPushButton(this);
//设置文本背景及字体大小颜色
btn1->setText("登录");
btn1->setFont(font);
btn1->setStyleSheet("background-color:rgb(0,116,228);color:white;");
//按钮大小位置
btn1->move(70,480);
btn1->resize(450,80);
//密码文本框按钮:是否显示文本
QPushButton *btn2 = new QPushButton(edit2);
btn2->resize(50,50);
btn2->move(380,15);
//设置按钮背景
QLabel *lab = new QLabel(btn2);
lab->setPixmap(QPixmap(":/epic.png"));
lab->resize(50,50);
lab->move(0,0);
lab->setScaledContents(true);
}
mywidget::~mywidget()
{
}
![](https://i-blog.csdnimg.cn/direct/2e1dccba804a499fbfb7f5ec6b0ccde2.png)
my::my(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::my)
{
this->setWindowFlag(Qt::FramelessWindowHint);
ui->setupUi(this);
ui->label->setPixmap(QPixmap(":/png/preview2.png"));
ui->label->setScaledContents(true);
ui->password->setEchoMode(QLineEdit::Password);
this->setFixedSize(486,402);
connect(ui->log_in,SIGNAL(clicked),this,SLOT(on_log_in_clicked()));
}
my::~my()
{
delete ui;
}
void my::on_exit_clicked()
{
this->close();
}
void my::on_log_in_clicked()
{
QString id,password;
id = ui->account->text();
password = ui->password->text();
if(id == "admin" && password == "123456")
{
qDebug() << "登陆成功!" << endl;
this->close();
}
else
{
qDebug() << "登陆失败!" << endl;
ui->account->clear();
ui->password->clear;
}
}
![](https://i-blog.csdnimg.cn/direct/68f592b2acde43a0a787ed707ceb7f85.png)
![](https://i-blog.csdnimg.cn/direct/6d7d0948d4194868a4c8a32c0408dcee.png)