聊天界面的弹窗

聊天界面的弹窗_第1张图片

 

#include "mywnd.h"
#include "ui_mywnd.h"

MyWnd::MyWnd(QWidget *parent): QWidget(parent), ui(new Ui::MyWnd)
{
    ui->setupUi(this);
    QSize s =this->size();
    qDebug()<size()<setFixedSize(650,500);
    this->setWindowTitle("QQ");
    this->setWindowIcon(QIcon("C:\\Users\\Administrator\\Desktop\\qq.png"));
    //this->setBackgroundRole(QPalette::Dark);
    this->setAutoFillBackground(true);//允许填充
  //this->setStyleSheet("background-color:rgb(0,0,255)");
  //  this->setStyleSheet("background-color:yellow");
   // this->setWindowFlag(Qt::FramelessWindowHint);

    QPushButton *btn1 = new QPushButton(this);
    btn1->resize(80,30);
    btn1->setText("登录");
    btn1->move(220,350);

    QPushButton *btn2 = new QPushButton(this);
    btn2->resize(80,30);
    btn2->setText("取消");
    btn2->move(300,350);

    QPushButton *btn3 = new QPushButton(this);
    btn3->resize(40,40);
    btn3->move(80,220);
    //btn3->setStyleSheet("background-color:yellow");
    btn3->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\qq.png"));
    btn3->setEnabled(false);

    QPushButton *btn4 = new QPushButton(this);
    btn4->resize(40,40);
    btn4->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\qq2.png"));
    btn4->move(80,250);
    btn4->setEnabled(false);

    QPushButton *btn5 = new QPushButton(this);
    btn5->resize(110,110);
    btn4->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\qq3.png"));
    btn4->move(80,80);
    btn4->setEnabled(false);
    //定义编辑器
    QLineEdit *edt1 = new QLineEdit(this);
    edt1->move(150,220);
    edt1->resize(200,40);
    //edt1->setEchoMode(QLineEdit::Password);

    QLineEdit *edt2 = new QLineEdit(this);
    edt2->move(150,250);
    edt2->resize(200,40);
    edt2->setEchoMode(QLineEdit::Password);

    //自定义链接槽与信号
    connect(this,&MyWnd::mysignal,[](QString e){
       qDebug()<text();
        QString arr2=edt2->text();
        if(arr1 == "qwer" && arr2 == "1234")
        {qDebug()<<"登陆成功";
            QMessageBox box(QMessageBox::Information,
                            "提示",  //标题
                            "登录成功",//文本内容
                            QMessageBox::Ok, //按钮
                            this);
            int ret = box.exec();
            if(ret == QMessageBox::Ok)
            {
                close();
                emit mysignal("hello world");
            }
        }
        else {qDebug()<<"登陆失败";
               int ret  =  QMessageBox::warning(this,"提示","账号密码不匹配,是否重新登录",QMessageBox::Ok | QMessageBox::Cancel);
               if(ret == QMessageBox::Ok)
               {edt2->clear();}
               else{close();}
               return ;
        }
    }
    );

    connect
            ( btn2,
              &QPushButton::clicked,
              [&](){
        int ret  =  QMessageBox::warning(this,"提示","是否确定退出",QMessageBox::Yes | QMessageBox::No);
        if(ret == QMessageBox::Yes)
        {close();}
    }
    );
}
MyWnd::~MyWnd()
{
    delete ui;
}

你可能感兴趣的:(c++)