QMessageBox msgBox
QMessageBox msgBox;
QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
QPushButton *abortButton2 = msgBox.addButton(QMessageBox::Ok);
msgBox.exec();
if (msgBox.clickedButton() == connectButton)
{
qDebug() << "connect";
}
else if (msgBox.clickedButton() == abortButton)
{
qDebug() << "abort";
}
else if (msgBox.clickedButton() == abortButton2)
{
qDebug() << "OK";
}
---------------------------------------------------------------------------
QMessageBox::information(this,"Wrong com port" ,"Please check comport");
---------------------------------------------------------------------------
QMessageBox msgBox;msgBox.setText("Le document a été modifié.");msgBox.setInformativeText("Voulez-vous enregistrer les changements ?");msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);msgBox.setDefaultButton(QMessageBox::Save);int ret = msgBox.exec();switch (ret) {case QMessageBox::Save:// Clic sur Enregistrerbreak;case QMessageBox::Discard:// Clic sur Ne pas enregistrerbreak;case QMessageBox::Cancel:// Clic sur Annulerbreak;default:// ne doit pas se produirebreak;}
---------------------------------------------------------------
#include <QApplication> #include <QMessageBox> #include <QDebug> // ... void MyWidget::someSlot() { QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "Test", "Quit?", QMessageBox::Yes|QMessageBox::No); if (reply == QMessageBox::Yes) { qDebug() << "Yes was clicked"; QApplication::quit(); } else { qDebug() << "Yes was *not* clicked"; } }
--------------------------------------------------
QMessageBox msgBox;msgBox.setText("คุณต้องการจะทำรายการต่อไปใช่หรือไม่ ?");QPushButton *btnYes = msgBox.addButton(tr("Yes"), QMessageBox::ActionRole);QPushButton *btnNo = msgBox.addButton(tr("No"),QMessageBox::ActionRole);msgBox.exec();if (msgBox.clickedButton() == btnYes){
qDebug() << "YES";}
else if (msgBox.clickedButton() == btnNo){
qDebug() << "NO";}
---------------------------------------------------------------------------
http://doc.qt.io/qt-4.8/qmessagebox.html
http://qt.developpez.com/doc/4.7/qmessagebox/#icon-enum
0 ความคิดเห็น:
แสดงความคิดเห็น
สมัครสมาชิก ส่งความคิดเห็น [Atom]
<< หน้าแรก