Skip to content

Instantly share code, notes, and snippets.

@Atsushi4
Created September 6, 2012 06:57
Show Gist options
  • Save Atsushi4/3652304 to your computer and use it in GitHub Desktop.
Save Atsushi4/3652304 to your computer and use it in GitHub Desktop.
Use QMessageBox.
#include <QtGui>
class MainWindow : public QDialog
{
Q_OBJECT
public:
MainWindow()
{
QPushButton *b;
setLayout(new QGridLayout);
layout()->addWidget(b = new QPushButton("&show"));
connect(b, SIGNAL(clicked()), SLOT(showDialog()));
}
public slots:
void showDialog()
{
QString html = "<B>Score</B> : 100<BR>"
"<B>Score</B> : 200";
QMessageBox *box = new QMessageBox(QMessageBox::NoIcon
, "title"
, html
, QMessageBox::Ok | QMessageBox::Reset
, this);
box->setDefaultButton(QMessageBox::Ok);
switch (box->exec())
{
case QMessageBox::Ok:
qDebug() << "Ok"; break;
case QMessageBox::Reset:
qDebug() << "Reset"; break;
default:
qDebug() << "Unknown";
}
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}
#include "messagebox_sample.moc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment