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();
}
效果图:

Qt之消息对话框的更多相关文章
- Qt——消息对话框的设计
1.消息对话框是什么 消息对话框(MessageBox)提供了一个模态对话框,用来通知用户某些信息,或者用来询问用户一个问题并获得一个答复. 先看下面2张图—— 第一张图是网易云音乐的界面截图,在删除 ...
- QT学习 之 对话框 (四) 字体对话框、消息对话框、文件对话框、进程对话框(超详细中文注释)
QMessageBox类: 含有Question消息框.Information消息框.Warning消息框和Critical消息框等 通常有两种方式可以来创建标准消息对话框: 一种是采用“基于属性”的 ...
- 第八章 Qt GUI之对话框使用
第八章 Qt GUI之对话框使用 对话框可以是模态(modal)的或非模态(modeless)两种.当我们在一个用户界面程序里面对一个对话框(比如选择文件对话框)的操作没有结束前,界面的其他窗口无法操 ...
- JavaScript入门篇 第二天(消息对话框+网页弹出)
提问(prompt 消息对话框) prompt弹出消息对话框,通常用于询问一些需要与用户交互的信息.弹出消息对话框(包含一个确定按钮.取消按钮与一个文本输入框). 语法: prompt(str1, s ...
- MFC编程入门之十六(对话框:消息对话框)
前面几节讲了属性页对话框,我们可以根据所讲内容方便的建立自己的属性页对话框.本节讲解Windows系统中最常用最简单的一类对话框--消息对话框. 我们在使用Windows系统的过程中经常会见到消息对话 ...
- [转载]ExtJs4 笔记(6) Ext.MessageBox 消息对话框
作者:李盼(Lipan) 出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法 ...
- 弹出消息对话框ScriptManager
//直接调用WebMessageBox方法 #region 弹出消息对话框 /// <summary> /// 弹出消息对话框 /// </summary> /// <p ...
- 【转】Delphi的消息对话框
Delphi的消息对话框 输入输出inputBox()函数MessageBox()ShowMessage 对话框是Windows操作系统中程序与用户沟通的一种常见的交互方式,对话框可以向用户提供当前程 ...
- 确认(confirm 消息对话框)
confirm 消息对话框通常用于允许用户做选择的动作(包括一个确定按钮和一个取消按钮). 语法: confirm(str) str:在消息对话框中要显示的文本 返回值: 当用户点击"确定& ...
随机推荐
- IDEA中springboot项目添加yml格式配置文件
1.先创建application.properties 文件,在resources文件夹,右键 new -> Resource Bundle 如下图所示,填写名称 2.生成如下图所示文件 3. ...
- thymeleaf标签在js中调用转义变量与不转义变量写法
转义写法 [[${content.title}]] 不转义写法 有时候我们可能需要在页面上显示html代码 这样的话 就不能把字符串转义了 这时候可以采用下面这种写法 [(${content.txt} ...
- 【LeetCode】1466. 重新规划路线 Reorder Routes to Make All Paths Lead to the City Zero (Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://lee ...
- 【LeetCode】1166. Design File System 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 目录树 日期 题目地址https://leetc ...
- 【LeetCode】760. Find Anagram Mappings 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...
- 【LeetCode】174. Dungeon Game 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetc ...
- 【LeetCode】479. Largest Palindrome Product 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告(Python)
[LeetCode]659. Split Array into Consecutive Subsequences 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...
- Cornfields(poj2019)
Cornfields Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6798 Accepted: 3315 Descri ...
- 1269 - Consecutive Sum
1269 - Consecutive Sum PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 64 MB ...