
login
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
user.cpp \
widget.cpp
HEADERS += \
user.h \
widget.h
FORMS += \
user.ui \
widget.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
sor.qrc
form.h
#ifndef FORM_H
#define FORM_H
#include <QWidget>
namespace Ui {
class Form;
}
class Form : public QWidget
{
Q_OBJECT
public:
explicit User(QWidget *parent = nullptr);
~User();
public slots:
void login();
private:
Ui::Form *ui;
};
#endif // FORM_H
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimer>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
signals:
void log_sig();
public slots:
void btn_closed();
void btn_hide();
private slots:
void on_pushButton_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
main.cpp
#include "widget.h"
#include "form.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
Form u;
QObject::connect(&w,&Widget::log_sig,&u,&Form::login);
return a.exec();
}
form.cpp
#include "form.h"
#include "ui_user.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
}
Form::~Form()
{
delete ui;
}
void Form::login()
{
this->show();
}
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);
QObject::connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(btn_closed()));
QObject::connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(btn_hide()));
}
Widget::~Widget()
{
delete ui;
}
void Widget::btn_closed()
{
this->close();
}
void Widget::btn_hide()
{
this->showMinimized();
}
void Widget::on_pushButton_clicked()
{
if(ui->lineEdit->text() == "admin" && ui->lineEdit_2->text() == "12345")
{
ui->label_3->setStyleSheet(QString("background-color:blue;color:white"));
ui->label_3->setText("登陆成功");
emit log_sig();
QTimer::singleShot(600, this, [this]()
{
ui->label_3->setStyleSheet(QString("background:transparent;"));
this->close();
});
}
else
{
ui->label_3->setText("登陆失败");
ui->label_3->setStyleSheet(QString("background-color:red;color:black"));
QTimer::singleShot(600, this, [this]()
{
ui->label_3->setStyleSheet(QString("background:transparent;"));
ui->label_3->setText("");
ui->lineEdit_2->setText("");
});
}
}
form.ui

767

被折叠的 条评论
为什么被折叠?



