2024/02/08

使用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
    {

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值