#include "widget.h"
#include "ui_widget.h"
void Widget::my_slot()
{}
Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);this->setWindowIcon(QIcon(":/wodepeizhenshi.png"));//設置窗口的iconthis->setWindowTitle("鵬哥快聊");//更改名字this->setFixedSize(500,400);//設置尺寸QLabel *ql=new QLabel(this);//創建一個標簽ql->resize(QSize(500,200));//設置標簽大小ql->setPixmap(QString(":/logo.png"));ql->setScaledContents(true);QLabel *ql1=new QLabel(this);//創建一個標簽QLabel *ql2=new QLabel(this);//創建一個標簽edit1= new QLineEdit(this);//創建一個行編輯器edit2= new QLineEdit(this);//創建一個行編輯器edit1->resize(200,40);//為含編輯器設置尺寸edit2->resize(200,40);edit1->move(270,230);//含編輯器的位置edit2->move(edit1->x(),edit1->y()+50);edit1->setPlaceholderText("QQ/手機/郵箱");//設置展位文本edit2->setPlaceholderText("密碼");edit2->setEchoMode(QLineEdit::Password);//設置囘顯模式ql1->resize(40,40);//設置標簽的大小ql2->resize(40,40);ql1->move(210,edit1->y());ql2->move(210,edit2->y());ql1->setPixmap(QString(":/userName.jpg"));ql2->setPixmap(QString(":/passwd.jpg"));ql1->setScaledContents(true);ql2->setScaledContents(true);//創建兩個按鈕用輸入賬號密碼QPushButton *btn1= new QPushButton(this);QPushButton *btn2= new QPushButton(this);btn1->resize(QSize(70,40));//設置按鈕的大小btn2->resize(btn1->size());btn1->move(300,360);//按鈕位置btn2->move(btn1->x()+80,btn1->y());btn1->setText("登錄");btn2->setText("取消");btn1->setIcon(QIcon(":/login.png"));//導入按鈕圖片btn2->setIcon(QIcon(":/cancel.png"));connect(btn1,&QPushButton::clicked,this,&Widget::fun);connect(btn2,&QPushButton::clicked,this,&Widget::fun1);}
void Widget::fun()
{if(this->edit1->text()=="admin"&&this->edit2->text()=="123456"){qDebug()<<"deng lu cheng gong";emit jump();//跳转信号this->close();//关闭界面}else{qDebug()<<"deng lu shi bai";Widget::edit2->clear();}
}
void Widget::fun1()
{this->close();
}Widget::~Widget()
{delete ui;
}
#include "widget.h"
#include "form.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;w.show();Form f;Widget::connect(&w,&Widget::jump,&f,&Form::jump_slot);return a.exec();
}
#include "form.h"
#include "ui_form.h"Form::Form(QWidget *parent) :QWidget(parent),ui(new Ui::Form)
{ui->setupUi(this);
}
void Form::jump_slot()
{this->show();
}
Form::~Form()
{delete ui;
}
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QDebug>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECT
signals:void my_signal();//自定义信号void jump();//用于跳转信号
public slots:void my_slot();//自定义槽函数void fun();void fun1();
public:Widget(QWidget *parent = nullptr);~Widget();
private:Ui::Widget *ui;QLineEdit *edit1;QLineEdit *edit2;};
#endif // WIDGET_H