首页 > 其他分享 >11、QMessageBox(消息对话框)

11、QMessageBox(消息对话框)

时间:2023-12-08 14:13:03浏览次数:28  
标签:11 glayout QMessageBox 对话框 setText Dialog dispLabel new

 

 

 

 

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{


    ui->setupUi(this);
    resize(320,150);
    glayout = new QGridLayout(this);
    dispLabel = new QLabel("请选择标签");
    questionButton= new QPushButton("Question");
    informationButton= new QPushButton("Information");
    warningButton= new QPushButton("Warning");
    criticalButton= new QPushButton("Critical");
    aboutButton= new QPushButton("About");
    aboutqtButton= new QPushButton("AboutQt");

    glayout->addWidget(dispLabel,0,0 );
    glayout->addWidget(questionButton,1,0);
    glayout->addWidget(informationButton,1,1);
    glayout->addWidget(warningButton,2,0);
    glayout->addWidget(criticalButton,2,1);
    glayout->addWidget(aboutButton,3,0);
    glayout->addWidget(aboutqtButton,3,1);


    connect(questionButton,SIGNAL(clicked()),this,SLOT(displayQuestionMsg()));
    connect(informationButton,SIGNAL(clicked()),this,SLOT(displayInformationMsg()));
    connect(warningButton,SIGNAL(clicked()),this,SLOT(displayWarningMsg()));
    connect(criticalButton,SIGNAL(clicked(bool)),this,SLOT(displayCriticalMsg()));
    connect(aboutButton,SIGNAL(clicked(bool)),this,SLOT(displayAboutMsg()));
    connect(aboutqtButton,SIGNAL(clicked(bool)),this,SLOT(displayAboutQtMsg()));
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::displayQuestionMsg()
{
    dispLabel->setText("Question");
    switch(QMessageBox::question(this,"Question消息框","你是否想退出应用程序",
                                 QMessageBox::Ok|QMessageBox::Cancel
                                 ))
    {
    case QMessageBox::Ok:
        dispLabel->setText("Question->Ok");
        break;
    case QMessageBox::Cancel:
        dispLabel->setText("Question->cancel");
        break;
    default:
        break;
    }
    return;
}

void Dialog::displayInformationMsg()
{
    dispLabel->setText("Infomation");
    QMessageBox::information(this,"Infomation消息框","Infomation测试");
}

void Dialog::displayWarningMsg()
{
    dispLabel->setText("warning");
    switch (QMessageBox::warning(this,"Warning消息框","Warning测试",QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,QMessageBox::Save)) {
    case QMessageBox::Save:
        dispLabel->setText("warning->save");
        break;
    case QMessageBox::Discard:
        dispLabel->setText("warning->Discard");
        break;
    case QMessageBox::Cancel:
        dispLabel->setText("warning->Cancel");
        break;
    default:
        break;
    }
}

void Dialog::displayCriticalMsg()
{
    dispLabel->setText("cirtical");
    QMessageBox::critical(this,"cirtical消息框","cirtical测试");
}

void Dialog::displayAboutMsg()
{
dispLabel->setText("About");
QMessageBox::about(this,"about消息框","about测试");
}

void Dialog::displayAboutQtMsg()
{
    dispLabel->setText("AboutQT");
    QMessageBox::aboutQt(this,"about QT消息框测试");
}

 

标签:11,glayout,QMessageBox,对话框,setText,Dialog,dispLabel,new
From: https://www.cnblogs.com/baisedeyu/p/17887040.html

相关文章

  • 20211314王艺达 实验四 2
    任务详情基于华为鲲鹏云服务器CentOS中(或Ubuntu),使用LinuxSocket实现:Web服务器的客户端服务器,提交程序运行截图实现GET即可,请求,响应要符合HTTP协议规范服务器部署到华为云服务器,浏览器用本机的把服务器部署到试验箱。(加分项)具体实现代码:copy.c:/*copy.c:**Copyright......
  • 2023-2024-1 20211327 实验四 Web服务器2
    实验四Web服务器2Web服务器的客户端服务器web_server.c#include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<arpa/inet.h>#definePORT8080#defineBUFFER_SIZE1024voidhandle_client(intclient_socket){......
  • vmware 安装 window11跳过TPM
    HKEY_LOCAL_MACHINE\SYSTEM\Setup创建一个名为“LabConfig”的项,在“LabConfig”下创建两个32位DWORD值:键为“BypassTPMCheck”,值为“00000001”键为“BypassSecureBootCheck”,值为“00000001”在安装Windows11进入到以下阶段即“现在安装”按Shift+F10进入......
  • 2023-2024-1 20211327 实验四 Web服务器1-socket编程
    实验四Web服务器1-socket编程time服务器的客户端服务器time_server.c#include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<arpa/inet.h>#include<sys/socket.h>#include<sys/types.h>#include<s......
  • 10、QInputDialog(输入对话框)
     private:QGridLayout*glayout;QPushButton*inputStudentNoButton;QLineEdit*inputStudentNoButtonLine;QPushButton*inputStudentNameButton;QLineEdit*inputStudentNameButtonLine;QPushButton*inputStudentSexButton;QLine......
  • 20211314王艺达 实验四 1
    1.time服务器的客户端服务器,提交程序运行截图查看ipcsapp.c:#include<netinet/in.h>#include<arpa/inet.h>#include<netdb.h>#include<sys/types.h>#include<sys/socket.h>#include<stdlib.h>#include<string.h>#include<errno.......
  • 9、QFontDialog(字体对话框)
     #ifndefDIALOG_H#defineDIALOG_H#include<QDialog>#include<QPushButton>#include<QLineEdit>#include<QFontDialog>#include<QGridLayout>classDialog:publicQDialog{Q_OBJECTpublic:Dialog(QWidget*parent......
  • VMware17 ubuntu18.04.5安装好后无法访问win11共享文件夹的问题
    1在关闭虚拟机的情况下,点击虚拟机设置,CD/DVD设置使用ISO镜像文件,并设置好镜像路径。2启动虚拟机,此时重新安装VMwaretools按钮变成有效状态,点击该按钮,如果虚拟机进入系统后,该按钮会变成无效状态。3等待虚拟机自动下载VMwaretools,下载后在桌面可以看到VMwaretoolsDVD光盘,......
  • P1119 灾后重建
    原题链接思路请看题解,讲的非常详细,细节请看我一道很多细节的题1.初始化要赋1e92.只有在两个村庄都重建完之后,一条路才通3.一条路都通了之后,两个村庄都要再走一遍4.村庄编号从0开始,而不是从1开始5.弹出重建完成的村庄时,迭代器it记得加上判断不超过n,因为t为零时永远小于when......
  • P5314 [Ynoi2011] ODT
    好题,牛牛的一个套路。先树剖一下,我们可以很简单的用树状数组维护每个点的真实值。对于每个点只维护所有轻儿子的信息,对于每次询问的时候暴力加入当前点,重儿子以及父亲的信息,查询第\(k\)大,再删除信息即可。考虑链修改的影响。因为只维护的是轻儿子的信息,那么只有链上的所有轻......