zoukankan      html  css  js  c++  java
  • QT的常用对话框的应用

    QMessageBox类提供了常用的弹出式对话框:提示、警告、错误、询问、关于对话框

    需要添加头文件 

    #include <QMessageBox>

    MESSAGE  是要是显示的字符串

        void Dialog::criticalMessage()  
        {  
            QMessageBox::StandardButton reply;  
            reply = QMessageBox::critical(this, tr("QMessageBox::critical()"),  
                                            MESSAGE,  
                                            QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);  
            if (reply == QMessageBox::Abort)  
                criticalLabel->setText(tr("Abort"));  
            else if (reply == QMessageBox::Retry)  
                criticalLabel->setText(tr("Retry"));  
            else  
                criticalLabel->setText(tr("Ignore"));  
        }  
          
        void Dialog::informationMessage()  
        {  
            QMessageBox::StandardButton reply;  
            reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);  
            if (reply == QMessageBox::Ok)  
                informationLabel->setText(tr("OK"));  
            else  
                informationLabel->setText(tr("Escape"));  
        }  
          
        void Dialog::questionMessage()  
        {  
            QMessageBox::StandardButton reply;  
            reply = QMessageBox::question(this, tr("QMessageBox::question()"),  
                                            MESSAGE,  
                                            QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);  
            if (reply == QMessageBox::Yes)  
                questionLabel->setText(tr("Yes"));  
            else if (reply == QMessageBox::No)  
                questionLabel->setText(tr("No"));  
            else  
                questionLabel->setText(tr("Cancel"));  
        }  
          
        void Dialog::warningMessage()  
        {  
            QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),  
                               MESSAGE, 0, this);  
            msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);  
            msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);  
            if (msgBox.exec() == QMessageBox::AcceptRole)  
                warningLabel->setText(tr("Save Again"));  
            else  
                warningLabel->setText(tr("Continue"));  
          
        }  
  • 相关阅读:
    我今天能懂
    SpringMVC之RequestContextHolder分析
    idea只导入部分依赖
    idea中GitPush失败问题
    SpringBoot常用配置,引入外部配置文件信息,热加载
    idea的yml文件不识别问题
    SpringBoot介绍,快速入门小例子,目录结构,不同的启动方式,SpringBoot常用注解
    Java连接Redis,存储对象获取对象()byte和json),连接池
    Nginx的反向代理
    Nginx介绍,安装,配置
  • 原文地址:https://www.cnblogs.com/wanghuixi/p/7000764.html
Copyright © 2011-2022 走看看