使用QT编写一个简单QQ登录界面
#ifndef MYWIDGET_H
#define MYWIDGET_H
#include <QWidget>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class MyWidget; }
QT_END_NAMESPACE
class MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent = nullptr);
~MyWidget();
private slots:
void on_btnClose_clicked();
void on_btn_clicked();
void on_btnLogin_clicked();
void on_btnCancel_clicked();
private:
Ui::MyWidget *ui;
signals:
void sig_login();
};
#endif // MYWIDGET_H
#include "mywidget.h"
#include "ui_mywidget.h"
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::MyWidget)
{
ui->setupUi(this);
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
}
MyWidget::~MyWidget()
{
delete ui;
}
void MyWidget::on_btnClose_clicked()
{
}
void MyWidget::on_btn_clicked()
{
}
void MyWidget::on_btnLogin_clicked()
{
if(ui->lineEditUserName->text() == "admin" && ui->lineEditPassword->text() == "123456")
{
QMessageBox msg(QMessageBox::Information,
"Information",
"login sucessfully!",
QMessageBox::Ok,
this);
int res = msg.exec();
if(res == QMessageBox::Ok)
{
emit this->sig_login();
this->close();
}
}
else
{
QMessageBox msg(QMessageBox::Question,
"Question",
"wrong user name or password, try again?",
QMessageBox::Yes|QMessageBox::No,
this);
int res = msg.exec();
if(res == QMessageBox::Yes)
{
ui->lineEditPassword->clear();
}
else
{
this->close();
}
}
}
void MyWidget::on_btnCancel_clicked()
{
int res = QMessageBox::question(this,
"Question",
"will quit login?",
QMessageBox::Yes|QMessageBox::No);
if(res == QMessageBox::Yes)
{
this->close();
}
else
{
}
}