zoukankan      html  css  js  c++  java
  • Qt之消息对话框

    widget.h:

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    #include<QLineEdit>
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = 0);
        ~Widget();
    public slots:
        void Jiemian_buju_Init();
        void showdanger();
        void showinform();
        void showquestion();
    private:
        QLineEdit * qLedit1;
        QLineEdit* qLedit2;
    };
    
    #endif // WIDGET_H

    widget.cpp:

    #include "widget.h"
    #include<QMessageBox>
    #include<QPushButton>
    #include<QVBoxLayout>
    #include<QLineEdit>
    #include<QGridLayout>
    #include<QLabel>
    #include<QDebug>
    Widget::Widget(QWidget *parent):QWidget(parent)
    {
        Jiemian_buju_Init();
    }
    Widget::~Widget()
    {
    
    
    }
    void  Widget::Jiemian_buju_Init()
    {
        QGridLayout *qg=new QGridLayout(this);
    
        QLabel *qL1=new QLabel("用户名:");
        QLabel *qL2=new QLabel("密码:");
    
    qLedit1=new QLineEdit;
    qLedit2=new QLineEdit;
    
    qLedit2->setEchoMode(QLineEdit::Password);
    
        QPushButton *qb1=new QPushButton("确认:");
        QPushButton *qb2=new QPushButton("取消:");
        qg->addWidget(qL1,0,0,1,1);
        qg->addWidget(qL2,1,0,1,1);
        qg->addWidget(qLedit1,0,1,1,1);
        qg->addWidget(qLedit2,1,1,1,1);
    
        qg->addWidget(qb1,2,0,1,1);
        qg->addWidget(qb2,2,1,1,1);
    
        this->setLayout(qg);
    
    
       connect(qb1,SIGNAL(clicked()),this,SLOT(showdanger()));
       connect(qb2,SIGNAL(clicked()),this,SLOT(showquestion()));
    
    
    }
    void Widget::showdanger()
    {
       if((qLedit1->text()=="admin")&&(qLedit2->text()=="123456"))
       {
                showinform();
       }
       else {
           QMessageBox::warning(this,"warning","密码错误,登录失败!");
       }
    
    }
    void Widget::showinform()
    {
    QMessageBox::information(this,"information","登录成功!");
    }
    void Widget::showquestion()
    {
          int s=QMessageBox::question(this,"question","确认退出吗?",QMessageBox::Open|QMessageBox::Save);
          qDebug()<<s<<endl;
       if(s==2048)
       {
           close();
       }
    
    }

    main.cpp:

    #include "widget.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
    
        return a.exec();
    }

    效果图:

  • 相关阅读:
    BZOJ 2738 矩阵乘法(整体二分+二维树状数组)
    BZOJ 1430 小猴打架(prufer编码)
    BZOJ 2818 Gcd(莫比乌斯反演)
    BZOJ 4403 序列统计(Lucas)
    BZOJ 3083 遥远的国度(树链剖分+线段树)
    BZOJ 2049 [Sdoi2008]Cave 洞穴勘测(动态树)
    BZOJ 3282 Tree(动态树)
    BZOJ 3239 Discrete Logging(BSGS)
    BZOJ 2683 简单题(CDQ分治+树状数组)
    BZOJ 4327 JSOI2012 玄武密码(后缀自动机)
  • 原文地址:https://www.cnblogs.com/SunShine-gzw/p/13267234.html
Copyright © 2011-2022 走看看