Qt QMessageBox::information 自定义按钮


一.基本简介

在使用QT的弹窗提示时,习惯使用

QMessageBox::information

QMessageBox::question

QMessageBox::warning

QMessageBox::critical

一般对于按钮,是使用系统提供的默认按钮 例如:QMessageBox::Ok|QMessageBox::Cancel 等

二.如果要自己定义按钮,使用自定义的按钮文字,该怎么做?

答案其实很简单,以information举例,如下代码:

1 static int information(QWidget *parent, const QString &title, 2 const QString& text, 3 int button0, int button1 = 0, int button2 = 0); 4 5 static int information(QWidget *parent, const QString &title, 6 const QString& text, 7 const QString& button0Text, 8 const QString& button1Text = QString(), 9 const QString& button2Text = QString(), 10 int defaultButtonNumber = 0, 11 int escapeButtonNumber = 1); 12 13 inline static StandardButton information(QWidget *parent, const QString &title, 14 const QString& text, 15 StandardButton button0, StandardButton button1 = NoButton)

使用案例

1 int btnStatus = QMessageBox::information(nulptr,tr("title"),tr("text"),tr("按钮1"),tr("按钮2")) 2 3 if(0 == btnStatus)//点击了按钮1(按钮索引位置为0,后面的依次增加) 4 7 else if(1 == btnStatus)//点击了按钮2(按钮索引位置为1) 8



上一篇:Qt 常用数据类型转换

下一篇:Qt5.12配置OpenCV教程


Qt
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图