• QMessageBox中的四种对话框


    QMessageBox中的四种对话框

    ui_dialogtest.h文件:

    /********************************************************************************
    ** Form generated from reading UI file 'dialogtest.ui'
    **
    ** Created by: Qt User Interface Compiler version 4.8.5
    **
    ** WARNING! All changes made in this file will be lost when recompiling UI file!
    ********************************************************************************/
    
    #ifndef UI_DIALOGTEST_H
    #define UI_DIALOGTEST_H
    
    #include <QtCore/QVariant>
    #include <QtGui/QAction>
    #include <QtGui/QApplication>
    #include <QtGui/QButtonGroup>
    #include <QtGui/QDialog>
    #include <QtGui/QHeaderView>
    #include <QtGui/QPushButton>
    #include <QtGui/QSplitter>
    
    QT_BEGIN_NAMESPACE
    
    class Ui_Dialog
    {
    public:
        QSplitter *splitter;
        QPushButton *informationButton;
        QPushButton *questionButton;
        QPushButton *warningButton;
        QPushButton *criticalButton;
    
        void setupUi(QDialog *Dialog)
        {
            if (Dialog->objectName().isEmpty())
                Dialog->setObjectName(QString::fromUtf8("Dialog"));
            Dialog->resize(337, 95);
            splitter = new QSplitter(Dialog);
            splitter->setObjectName(QString::fromUtf8("splitter"));
            splitter->setGeometry(QRect(10, 30, 300, 23));
            splitter->setOrientation(Qt::Horizontal);
            informationButton = new QPushButton(splitter);
            informationButton->setObjectName(QString::fromUtf8("informationButton"));
            splitter->addWidget(informationButton);
            questionButton = new QPushButton(splitter);
            questionButton->setObjectName(QString::fromUtf8("questionButton"));
            splitter->addWidget(questionButton);
            warningButton = new QPushButton(splitter);
            warningButton->setObjectName(QString::fromUtf8("warningButton"));
            splitter->addWidget(warningButton);
            criticalButton = new QPushButton(splitter);
            criticalButton->setObjectName(QString::fromUtf8("criticalButton"));
            splitter->addWidget(criticalButton);
    
            retranslateUi(Dialog);
    
            QMetaObject::connectSlotsByName(Dialog);
        } // setupUi
    
        void retranslateUi(QDialog *Dialog)
        {
            Dialog->setWindowTitle(QApplication::translate("Dialog", "Dialog", 0, QApplication::UnicodeUTF8));
            informationButton->setText(QApplication::translate("Dialog", "344277241346201257", 0, QApplication::UnicodeUTF8));
            questionButton->setText(QApplication::translate("Dialog", "346217220351227256", 0, QApplication::UnicodeUTF8));
            warningButton->setText(QApplication::translate("Dialog", "350255246345221212", 0, QApplication::UnicodeUTF8));
            criticalButton->setText(QApplication::translate("Dialog", "344270245351207215351224231350257257", 0, QApplication::UnicodeUTF8));
        } // retranslateUi
    
    };
    
    namespace Ui {
        class Dialog: public Ui_Dialog {};
    } // namespace Ui
    
    QT_END_NAMESPACE
    
    #endif // UI_DIALOGTEST_H

    dialogtest.h文件

    #ifndef DIALOGTEST_H
    
    #define DIALOGTEST_H
    #include <QDialog>
    #include "ui_dialogtest.h"
    class dialogTest : public QDialog,public Ui_Dialog
    {
        Q_OBJECT
    public:
        dialogTest(QWidget *parent = 0);
        private slots:
            void clickInformationButton();
            void clickWarningButton();
            void clickQuestionButton();
            void clickCriticalButton();
    };
    #endif

    dialogtest.c++文件

    #include <QtGui>
    #include <QMessageBox>
    #include "dialogtest.h"
    dialogTest::dialogTest(QWidget *parent): QDialog(parent)
    {
        setupUi(this);
        QTextCodec::setCodecForCStrings(QTextCodec::codecForName("gb2312"));
        warningButton->setEnabled(false);
        connect(informationButton, SIGNAL(clicked()), this, SLOT(clickInformationButton()));
        connect( warningButton, SIGNAL(clicked()), this, SLOT(clickWarningButton()));
        connect(questionButton, SIGNAL(clicked()), this, SLOT(clickQuestionButton()));
        connect(criticalButton, SIGNAL(clicked()), this, SLOT(clickCriticalButton()));
    }
    void dialogTest::clickCriticalButton(){
         int r = QMessageBox::critical(this, "严重警告","严重警告按钮将变成灰常",QMessageBox::Ok);
         if (QMessageBox::Ok == r){
             criticalButton->setEnabled(false);
             warningButton->setEnabled(true);
         }
    }
    void dialogTest::clickInformationButton()
    {
        QMessageBox::information(this, "信息","信息按钮会变化",QMessageBox::Ok);
        QString s = informationButton->text();
        if ("信息" == s)
               informationButton->setText("informtion");
        else
            informationButton->setText("信息");
    
    }
    void dialogTest::clickQuestionButton(){
        int r = QMessageBox::question(this, "提问","你确定退出吗?",QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok);
        if (QMessageBox::Ok == r)
            close();
    }
    void dialogTest::clickWarningButton(){
     int r = QMessageBox::warning(this, "警告","需要严重警告按钮回复正常吗",QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Cancel);
     if (QMessageBox::Ok == r){
         criticalButton->setEnabled(true);
         warningButton->setEnabled(false);
     }
    
    }

    main.c++文件:

    include <QtGui/QApplication>
    #include "dialogtest.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        dialogTest w;
        w.show();
        return a.exec();
    }

  • 相关阅读:
    asp.net 学习连接
    学习笔记一
    windows 2008 r2 AD密码策略
    Windows Server 2008 R2之活动目录回收站
    用java 调用 .net 自定义的 Soap WEB Service
    昆明赶街时间
    Windows Server 2008 R2 AD的备份和恢复
    AD 自定义属性
    AD、IIS、asp.net
    wsgen与wsimport命令说明
  • 原文地址:https://www.cnblogs.com/sklww/p/3810381.html
Copyright © 2020-2023  润新知