一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

一.基本简介

在使用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 {
 5     //do
 6 }
 7 else if(1 == btnStatus)//点击了按钮2(按钮索引位置为1)
 8 {
 9     //do
10 }

 

posted on 2024-03-06 13:39  一杯清酒邀明月  阅读(256)  评论(0编辑  收藏  举报