Qt4之消息对话框

用过flex编程的童鞋应该用过alert()消息框吧

下面我来介绍Qt中使用过的消息对话框,Q4消息对话框类型多而且功能比较强大。

1.Question消息框:

 switch(QMessageBox::question(this,"Question",tr("It's end of document,search from begin?"),
    		QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok))
    {
    case QMessageBox::Ok:
    	label->setText(" Question button / Ok ");
    	break;
    case QMessageBox::Cancel:
    	label->setText(" Question button / Cancel ");
    	break;
    default:
    	break;
    }

2.Information消息框:

 QMessageBox::information(this,"Information",tr("anything you want tell user"));

3.Warning消息框:

 switch(QMessageBox::warning(this,"Warning",tr("Save changes to document?"),
    		QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel,QMessageBox::Save))
    {
    case QMessageBox::Save:
    	label->setText(" Warning button / Save ");
    	break;
    case QMessageBox::Discard:
    	label->setText(" Warning button / Discard ");
    	break;
    case QMessageBox::Cancel:
    	label->setText(" Warning button / Cancel ");
    	break;
    default:
    	break;
    }

4.Critical消息框:

 QMessageBox::critical(this,"Critical",tr("tell user a critical error"));
    label->setText(" Critical MessageBox ");

5.About消息框:

QMessageBox::about(this,"About",tr("Message box example!"));
    label->setText(" About MessageBox ");

6.AboutQt消息框:

   QMessageBox::aboutQt(this,"About Qt");
    label->setText(" About Qt MessageBox ");

7.Custom消息框:

    QMessageBox customMsgBox;
    customMsgBox.setWindowTitle("Custom message box");
    QPushButton *lockButton = customMsgBox.addButton(tr("Lock"),QMessageBox::ActionRole);
    QPushButton *unlockButton = customMsgBox.addButton(tr("Unlock"),QMessageBox::ActionRole);
    QPushButton *cancelButton = customMsgBox.addButton(QMessageBox::Cancel);
    customMsgBox.setIconPixmap(QPixmap(":/images/linuxredhat.png"));
    customMsgBox.setText(tr("This is a custom message box"));
    customMsgBox.exec();
    
    if(customMsgBox.clickedButton() == lockButton)
    	label->setText(" Custom MessageBox / Lock ");
    if(customMsgBox.clickedButton() == unlockButton)
    	label->setText(" Custom MessageBox / Unlock ");
    if(customMsgBox.clickedButton() == cancelButton)
    	label->setText(" Custom MessageBox / Cancel ");


注意: 在使用的过程中,最前面不要忘了添加

    #include <QtGui>

待续.......

你可能感兴趣的:(编程,Flex,user,search,qt,button)