首页 > 代码库 > QT的常用对话框的应用
QT的常用对话框的应用
QMessageBox类提供了常用的弹出式对话框:提示、警告、错误、询问、关于对话框
需要添加头文件
#include <QMessageBox>
MESSAGE 是要是显示的字符串
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的常用对话框的应用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。