Qt-MessageBox类简单使用

基本描述

QMessageBox类提供了一个有一条简短消息、一个图标和一些按钮的模式对话框。
消息框用于提供情报信息并且问一些简单的问题。
QMessageBox提供了一个不同信息的范围,大致按两个轴进行排列:严重程度和复杂程度。
按严重程度分:消息;警告;错误。
按复杂程度分为一个按钮(确定)的简单消息、或者用于提问的两个或者甚至三个按钮。

简单使用

1、信息窗口

[static] int QMessageBox::information(QWidget *parent, const QString &title, 
                            const QString &text, 
                            int button0, int button1 = 0, int button2 = 0)

例:

int ret=QMessageBox::information(this, tr("My Application"),
                        tr("The time is over.\n"
                        "Do you complete?"),
                        QMessageBox::Yes | QMessageBox::No);

2、警告窗口

[static] int QMessageBox::warning(QWidget *parent, const QString &title, 
                            const QString &text,
                            int button0, int button1, int button2 = 0)

例:

int ret=QMessageBox::warning(this, tr("My Application"),
                tr("The schedule is empty.\n"
                "Add a schedule to the text."),
                QMessageBox::Ok);

或者自定义QMessageBox对象,使用成员函数。
例:

QMessageBox msgBox;
        msgBox.setText("The time is not over.");
        msgBox.setInformativeText("Do you want to cancel this schedule?");
        msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        int ret = msgBox.exec();

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值