您的位置:首页 > 其它

QMessageBox 的四种用法

2016-04-08 09:41 429 查看
之前的一些QT笔记,整理一下。

一、直接类名可访问的

[cpp] view
plain copy







void MainWindow::on_info_clicked()

{

//info

QMessageBox::information(this, "Title", "Text");

}

void MainWindow::on_question_clicked()

{

//question

QMessageBox::StandardButton reply;

reply = QMessageBox::question(this, "Title", "Do you like cat?", QMessageBox::Yes | QMessageBox::No);

if(reply == QMessageBox::Yes)

{

}

else

{

}

}

void MainWindow::on_warning_clicked()

{

//warning

QMessageBox::warning(this, "Title", "Text");

}

void MainWindow::on_pushButton_4_clicked()

{

QMessageBox::question(this, "Title", "Do you like cat?", QMessageBox::YesToAll|QMessageBox::Yes|QMessageBox::No);

}

二、构造对象来实现

[cpp] view
plain copy







class MyMessageBox : public QObject

{

public:

MyMessageBox();~MyMessageBox();

static void ChMessageOnlyOk_Information(QString info)

{

QMessageBox msg;

msg.setWindowTitle(tr("提示"));

msg.setText(info);

msg.setStyleSheet("font: 14pt;background-color:rgb( 0,220, 0)");

msg.setIcon(QMessageBox::Information);

msg.addButton(tr("确定"),QMessageBox::ActionRole);

msg.exec();

}

static void ChMessageOnlyOk_Error(QString info)

{

QMessageBox msg;

msg.setWindowTitle(tr("提示"));

msg.setText(info);

msg.setStyleSheet("font: 14pt;background-color:rgb(220, 0, 0)");

msg.setIcon(QMessageBox::Critical);

msg.addButton(tr("确定"),QMessageBox::ActionRole);

msg.exec();

}

static int ChMessageOkCancel(QString info)

{

QMessageBox msg;

msg.setWindowTitle(tr("提示"));

msg.setText(info);

msg.setStyleSheet("color:rgb(220, 0, 0);font: 14pt");

msg.setIcon(QMessageBox::Information);

msg.addButton(tr("确定"),QMessageBox::ActionRole);

msg.addButton(tr("取消"),QMessageBox::ActionRole);

return msg.exec();

}

};

int ret = MyMessageBox::ChMessageOkCancel(tr("是否继续?"));

if(1 == ret)

{

}

else if(0 == ret)

{

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: