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:在消息对话框中要显示的文本 返回值: 当用户点击"确定& ...
随机推荐
- 『学了就忘』Linux日志管理 — 93、日志轮替补充
目录 1.把自己的日志加入日志轮替 (1)操作方式 (2)示例 2.logrotate命令 1.把自己的日志加入日志轮替 使用RPM包方式安装服务的日志会自动的加入logrotate轮替,一般不需要你 ...
- RuoYi项目整合Mybatis-Plus 框架
RuoYi框架默认使用的是Mybatis框架 但是有的习惯使用MP框架,这就很不方便, 不过可以简单进行整合 引入依赖 <dependency> <groupId>com.ba ...
- 解决Xshell 连接Linux 窗口不活动会自动断开连接
修改linux服务器ssh断开时间 修改profile配置 vim /etc/profile 增加配置 后面单位秒 这里就是三分钟不活动断开连接 TMOUT=180 然后使用 wq! 进行保存,使 ...
- 【LeetCode】119. 杨辉三角 II Pascal‘s Triangle II(Python & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题思路 方法一: 空间复杂度 O ( k ∗ ( k + 1 ...
- 【九度OJ】题目1144:Freckles 解题报告
[九度OJ]题目1144:Freckles 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1144 题目描述: In an ...
- 【九度OJ】题目1474:矩阵幂 解题报告
[九度OJ]题目1474:矩阵幂 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1474 题目描述: 给定一个n*n的矩阵,求该矩阵的 ...
- D. Puzzles(Codeforces Round #362 (Div. 2))
D. Puzzles Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 ...
- 1161 - Extreme GCD
1161 - Extreme GCD PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB All ...
- 昆泰CH7511B方案|EDP转LVDS资料|CS5211pin to pin 替代CH7511B电路设计
Chrontel的CH7511B是一种低成本.低功耗的半导体器件,它将嵌入式DisplayPort信号转换为LVDS(低压差分信号).这款创新的DisplayPort接收机带有集成LVDS发射机,专为 ...
- bat文件调用CMD命令快速显示ip
代码如下: @echo off :main cls ipconfig @pause ipconfig 可改为其他CMD命令