情報
QMessageBox ::情報(NULL、" タイトル"、" コンテンツ"、QMessageBox ::はい| QMessageBox ::いいえ、QMessageBox ::はい)。
これは、次のような効果があり、使用の比較的一般的な種類です。
プロトタイプ情報:
StandardButton QMessageBox ::情報(QWidgetの*親、constの QStringの&タイトル、constの QStringの&テキスト、StandardButtonsボタン= OK、StandardButton defaultButtonの= NoButton)[ 静的 ]
- 最初のパラメータは、親コントロールへのポインタであります
- 2番目のパラメータはタイトルです
- 第三のパラメータがコンテンツであります
- 第四のパラメータは、ボタンの数(デフォルトはOKである)は、ウィンドウであります
- 5番目のパラメータは、入力押されたボタンを使用することを指定します。(デフォルトNoButtonは、QMessageBoxケースは、自動的に適切なデフォルトを選択します。)
例1:
QMessageBox ::情報(NULL、" タイトル"、" コンテンツ");
この時の効果、デフォルトパラメータとして、第四および第五:
例2:
QMessageBox ::情報(NULL、" タイトル"、" コンテンツ"、QMessageBox ::はい| QMessageBox ::いいえ)。
そして効果(図1と同じ。):
例3:
QMessageBox ::情報(NULL、" タイトル"、" コンテンツ"、QMessageBox ::はい| QMessageBox ::いいえ| QMessageBox ::中止)。
:、オペレータが接続されているの影響を|複数のボタンを追加します。
参照ボタンの種類:
1 enum StandardButton {
2 // keep this in sync with QDialogButtonBox::StandardButton
3 NoButton = 0x00000000,
4 Ok = 0x00000400,
5 Save = 0x00000800,
6 SaveAll = 0x00001000,
7 Open = 0x00002000,
8 Yes = 0x00004000,
9 YesToAll = 0x00008000,
10 No = 0x00010000,
11 NoToAll = 0x00020000,
12 Abort = 0x00040000,
13 Retry = 0x00080000,
14 Ignore = 0x00100000,
15 Close = 0x00200000,
16 Cancel = 0x00400000,
17 Discard = 0x00800000,
18 Help = 0x01000000,
19 Apply = 0x02000000,
20 Reset = 0x04000000,
21 RestoreDefaults = 0x08000000,
22
23 FirstButton = Ok, // internal
24 LastButton = RestoreDefaults, // internal
25
26 YesAll = YesToAll, // obsolete
27 NoAll = NoToAll, // obsolete
28
29 Default = 0x00000100, // obsolete
30 Escape = 0x00000200, // obsolete
31 FlagMask = 0x00000300, // obsolete
32 ButtonMask = ~FlagMask // obsolete
33 };
会创建消息提示框后,我们怎么知道用户点了什么呢,看如下小例子:
1 QMessageBox:: StandardButton result= QMessageBox::information(NULL, "Title", "Content",QMessageBox::Yes|QMessageBox::No);
2 switch (result)
3 {
4 case QMessageBox::Yes:
5 qDebug()<<"Yes";
6 break;
7 case QMessageBox::No:
8 qDebug()<<"NO";
9 break;
10 default:
11 break;
12 }
critical
critical adj. 关键的; 批评的,爱挑剔的; 严重的; 极重要的;
QMessageBox::critical(NULL, "critical", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
效果:
warning
QMessageBox::warning(NULL, "warning", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
效果:
question
QMessageBox::question(NULL, "question", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
效果:
about
原型:static void about(QWidget *parent, const QString &title, const QString &text);
QMessageBox::about(NULL, "About", "by hjwblog.com");
效果: