//for starf study
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<QMessageBox>
#include<QAbstractButton>
#include<QPushButton>
//QMessageBox 类提供了一个模式对话框,用于通知用户或向用户提问并接收答案。
//QMessageBox 是一个静态的类,可以直接访问其方法
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
/*
//系统提供的简便用法
QMessageBox::information(NULL, "Title", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
//第一个参数parent,说明它的父组件;第二个参数title,对话框的标题;
//第三个参数text,是对话框显示的内容;
//第四个参数buttons,声明对话框放置的按钮,默认是只放置一个OK按钮,这个参数可以使用或运算,例如我们希望有一个Yes和一个No的按钮,
//可以使用QMessageBox::Yes | QMessageBox::No,所有的按钮类型可以在QMessageBox声明的StandarButton枚举中找到;
//第五个参数defaultButton就是默认选中的按钮,默认值是NoButton,也就是哪个按钮都不选中。
//像这样的函数,QT还有四个,分别是:
QMessageBox::critical(NULL, "critical", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QMessageBox::warning(NULL, "warning", "Content");
QMessageBox::question(NULL, "question", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QMessageBox::about(NULL, "About", "About this application");
//他们都会创建一个弹出框,前4个,如果不填写后两个参数,那么就只会默认有一个OK按钮
//最后一个about只有如上三个参数,只有一个按钮,不可以设置选择按钮
//他们的功能是发起不同类型的提示:信息,错误,警告,询问,提示
*/
//如果要使用更丰富的弹出框
//就继承模态框类自定义
}
QMessageBox简单用法(QT5.12)
最新推荐文章于 2023-04-19 15:50:43 发布