QT常用控件(一) 您所在的位置:网站首页 对话框取消171-beta5 QT常用控件(一)

QT常用控件(一)

2023-06-22 09:05| 来源: 网络整理| 查看: 265

QDialog *dlg2 = new QDialog(); dlg2->resize(200, 200); dlg2->setAttribute(Qt::WA_DeleteOnClose);//关闭时清理内存 dlg2->show();

注意:在堆上就不能用点(.)了,要用->。而且由于使用 new 在堆上分配空间,却一直没有 delete。因此我们用setAttribute()函数设置对话框关闭时,自动销毁对话框。

2️⃣消息对话框 (QMessageBox)

 QMessageBox :模态对话框,用于显示信息、询问问题等;我们一般会使用该类提供的几个 static成员函数:(静态成员函数有两种访问方式:1 创建对象 ;2 直接通过类名去调用)

显示关于对话框 void about(QWidget * parent, const QString & title, const QString & text)

这是一个最简单的对话框,其标题是 title,内容是 text,父窗口是parent。对话框只有一个 OK 按钮。

显示错误对话框 StandardButton critical(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)

这个对话框将显示一个红色的错误符号。我们可以通过 buttons 参数指明其显示的按钮 。 默认情况下只有一个Ok按钮 ,我们可以使用StandardButtons 类型指定多种按钮,指令如下:

示例:

QMessageBox::critical(this, QStringLiteral("error"), QStringLiteral("错误"),QMessageBox::No);

第一个参数是 父类,第二个是标题,第三个是内容,第四个是按钮名称(类型为StandardButtons,可以有两个做选择),第五个参数是默认(按钮类型为StandardButtons)。

 

显示信息对话框 StandardButton information(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)

 示例:

QMessageBox::information(this, QStringLiteral("信息"), "infor", QMessageBox::Ok);

 

显示问题对话框 StandardButton question(QWidget * parent, const QString & title,const QString & text, StandardButtons buttons = StandardButtons( Yes | No ), StandardButton defaultButton = NoButton)

 示例:

//获取点击信息if (QMessageBox::Yes== QMessageBox::question(this, QStringLiteral("问题"), "question", QMessageBox::Yes | QMessageBox::No, QMessageBox::No)) { qDebug()


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有