0
点赞
收藏
分享

微信扫一扫

【Unity】Stream最好用的Selfhost开源轻量服务

进击的铁雾 03-23 13:30 阅读 2
命令模式

1.使用手动连接,将登录框中的取消按钮使用t4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数将登录按钮使用t5版本的连接到自定义的槽函数中,在槽函数中判断u界面上输入的账号是否为"admin",密码是否为"123456"如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空

head.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include<QPushButton>
#include<QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();



public slots:
    void on_cancle_clicked();

    void log_btnslot();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

main.cpp

#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->log_lab->setPixmap(QPixmap(":/pictrue/宿舍.png"));
    ui->log_lab->setScaledContents(true);

    ui->usrname_lab->setPixmap(QPixmap(":/pictrue/userName.jpg"));
    ui->usrname_lab->setScaledContents(true);
    ui->passwd_lab->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
    ui->passwd_lab->setScaledContents(true);

    ui->username_edit->setPlaceholderText("手机号/QQ号");
    ui->passwd_edit->setEchoMode(QLineEdit::Password);
    ui->passwd_edit->setPlaceholderText("密码");
    //登录按钮对应的槽函数
    connect(ui->log_btn,&QPushButton::clicked,this,&Widget::log_btnslot);


    //cancel按钮对应的曹函数
    connect(ui->cancle,SIGNAL(clicked()),this,SLOT(on_cancle_clicked()));
}

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

//cancel按钮对应的曹函数
void Widget::on_cancle_clicked()
{
    this->close();
}

void Widget::log_btnslot()
{
    if(ui->username_edit->text()=="admin"&ui->passwd_edit->text()=="123456")
    {
        qDebug()<<"登录成功";
 this->close();

    }else
    {
        qDebug()<<"登陆失败";
        ui->username_edit->clear();
        ui->passwd_edit->clear();

    }

}

运行结果:

2.自己完成一个使用qss的登陆窗口界面

*{
	
	background-color: rgb(255, 255, 255);
}
QFrame#frame{
	
	border-image: url(:/pic/yf.jpg);
	border-radius:30px;
	
}
#frame_2{
	border-radius:30px;
	
	background-color: rgba(138, 138, 138, 120);
}
QLabel#label{
	background:transparent;
	
	font: 75 9pt "ADMUI3Lg";
	
	color: rgb(0, 0, 0);
	
	font: 20pt "楷体";
}
QLineEdit{
	background:transparent;
	border:none;
	border-bottom:1px solid rgba(255, 255, 255, 200);
	
	font: 11pt "等线";
	color: rgba(255, 255, 255, 240);
	
	 
}
QPushButton{
	border-radius:10px;
	font: 15pt "等线";
	color: rgba(255, 255, 255, 200);
	
	background-color: rgb(170, 170, 127);
}
QPushButton:hover{
	border-radius:10px;
	font: 15pt "等线";
	color: rgba(255, 255, 255, 200);
	
	background-color: rgb(170, 170, 127);
}
QPushButton:pressed{
	border-radius:10px;
	font: 15pt "等线";
	color: rgba(255, 255, 255, 200);
	
	background-color: rgb(170, 170, 127);
	padding-top:5px;
	paddint-left:5px;
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //去掉头部
    this->setWindowFlag(Qt::FramelessWindowHint);
    //去掉空白
    this->setAttribute(Qt::WA_TranslucentBackground);
}

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

运行结果:

举报

相关推荐

0 条评论