提示、警告、错误、询问、关于对话框
2016-08-01 11:46
375 查看
QMessageBox类提供了常用的弹出式对话框:提示、警告、错误、询问、关于对话框
原型如下:
[cpp] view
plain copy
void about ( QWidget * parent, const QString & title, const QString & text )
void aboutQt ( QWidget * parent, const QString & title = QString() )
StandardButton critical ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton question ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
(1)title表示标题
(2)text是对话框中的内容信息
(3)buttons是要显示的按钮,它可以是:
[cpp] view
plain copy
NoButton = 0x00000000,
Ok = 0x00000400,
Save = 0x00000800,
SaveAll = 0x00001000,
Open = 0x00002000,
Yes = 0x00004000,
YesToAll = 0x00008000,
No = 0x00010000,
NoToAll = 0x00020000,
Abort = 0x00040000,
Retry = 0x00080000,
Ignore = 0x00100000,
Close = 0x00200000,
Cancel = 0x00400000,
Discard = 0x00800000,
Help = 0x01000000,
Apply = 0x02000000,
Reset = 0x04000000,
RestoreDefaults = 0x08000000,
(4)defaultButton是默认激活的按钮
(5)对话框的返回值即是用户最终点击的按钮。
示例:
[cpp] view
plain copy
void Dialog::criticalMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::critical(this, tr("QMessageBox::critical()"),
MESSAGE,
QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);
if (reply == QMessageBox::Abort)
criticalLabel->setText(tr("Abort"));
else if (reply == QMessageBox::Retry)
criticalLabel->setText(tr("Retry"));
else
criticalLabel->setText(tr("Ignore"));
}
void Dialog::informationMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);
if (reply == QMessageBox::Ok)
informationLabel->setText(tr("OK"));
else
informationLabel->setText(tr("Escape"));
}
void Dialog::questionMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("QMessageBox::question()"),
MESSAGE,
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (reply == QMessageBox::Yes)
questionLabel->setText(tr("Yes"));
else if (reply == QMessageBox::No)
questionLabel->setText(tr("No"));
else
questionLabel->setText(tr("Cancel"));
}
void Dialog::warningMessage()
{
QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
MESSAGE, 0, this);
msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
if (msgBox.exec() == QMessageBox::AcceptRole)
warningLabel->setText(tr("Save Again"));
else
warningLabel->setText(tr("Continue"));
}
界面:
原型如下:
[cpp] view
plain copy
void about ( QWidget * parent, const QString & title, const QString & text )
void aboutQt ( QWidget * parent, const QString & title = QString() )
StandardButton critical ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton question ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
(1)title表示标题
(2)text是对话框中的内容信息
(3)buttons是要显示的按钮,它可以是:
[cpp] view
plain copy
NoButton = 0x00000000,
Ok = 0x00000400,
Save = 0x00000800,
SaveAll = 0x00001000,
Open = 0x00002000,
Yes = 0x00004000,
YesToAll = 0x00008000,
No = 0x00010000,
NoToAll = 0x00020000,
Abort = 0x00040000,
Retry = 0x00080000,
Ignore = 0x00100000,
Close = 0x00200000,
Cancel = 0x00400000,
Discard = 0x00800000,
Help = 0x01000000,
Apply = 0x02000000,
Reset = 0x04000000,
RestoreDefaults = 0x08000000,
(4)defaultButton是默认激活的按钮
(5)对话框的返回值即是用户最终点击的按钮。
示例:
[cpp] view
plain copy
void Dialog::criticalMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::critical(this, tr("QMessageBox::critical()"),
MESSAGE,
QMessageBox::Abort | QMessageBox::Retry | QMessageBox::Ignore);
if (reply == QMessageBox::Abort)
criticalLabel->setText(tr("Abort"));
else if (reply == QMessageBox::Retry)
criticalLabel->setText(tr("Retry"));
else
criticalLabel->setText(tr("Ignore"));
}
void Dialog::informationMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::information(this, tr("QMessageBox::information()"), MESSAGE);
if (reply == QMessageBox::Ok)
informationLabel->setText(tr("OK"));
else
informationLabel->setText(tr("Escape"));
}
void Dialog::questionMessage()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("QMessageBox::question()"),
MESSAGE,
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (reply == QMessageBox::Yes)
questionLabel->setText(tr("Yes"));
else if (reply == QMessageBox::No)
questionLabel->setText(tr("No"));
else
questionLabel->setText(tr("Cancel"));
}
void Dialog::warningMessage()
{
QMessageBox msgBox(QMessageBox::Warning, tr("QMessageBox::warning()"),
MESSAGE, 0, this);
msgBox.addButton(tr("Save &Again"), QMessageBox::AcceptRole);
msgBox.addButton(tr("&Continue"), QMessageBox::RejectRole);
if (msgBox.exec() == QMessageBox::AcceptRole)
warningLabel->setText(tr("Save Again"));
else
warningLabel->setText(tr("Continue"));
}
界面:
相关文章推荐
- Qt入门-提示、警告、错误、询问、关于对话框
- Qt入门-提示、警告、错误、询问、关于对话框
- Qt入门-提示、警告、错误、询问、关于对话框
- 关于记事本[另存为]时,提示“共用对话框错误”的问题
- 关于LayoutInflater的错误用法(警告提示:Avoid passing null as the view root)
- 关于LayoutInflater的错误用法(警告提示:Avoid passing null as the view root)
- 关于LayoutInflater的错误用法(警告提示:Avoid passing null as the view root)
- 关于 “The import junit cannot be resolved”的提示错误
- 注意、提示、错误通用对话框函数
- 关于Validator错误提示字体小
- 教程:jQuery警告/确认/提示弹出对话框效果
- 关于用excel导出gridview控件中的数据时,会提示什么服务器控件 ,要在server等等的错误
- 给初学者关于eclilse汉化及tomcat错误的一点提示
- 关于sql server2000提示:SSL安全错误 connectionopen(secdoclienthandshake()) 的解决办法
- 关于在查询分析器下调试存储过程提示Sqlle.dll错误的一种解决办法
- 关于SQL SERVER 2000 提示"一般性网络错误" 的解决方法
- 关于网上流行的缓存类提示错误 '80040001' 的解决办法
- 记录一下,关于错误提示:could not find a part of path “X:\”的解决办法
- 关于“操作必须使用一个可更新的查询”错误提示!
- 关于ORACLE提示:"System.Data.OracleClient.OracleException: ORA-06550: 第 1 行, 第 7 列: \nPLS-00306: 调用 'xxxxxx' 时参数个数或类型错误\nORA-06550: 第 1 行, 第 7 列: \nPL/SQL: Statement ignored\n\r\n 的错误