QMessageBox的使用


/** 使用非靜態API,屬性設置API **/
    QMessageBox msgBox;
    msgBox.setWindowTitle("Note");/** 設置標題 **/
    msgBox.setText("The document has been modified.");
    msgBox.setInformativeText("Do you want to save your changes?");/** 設置更豐富一點的信息 **/
    msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);/** 添加標准按鈕 **/
    msgBox.setDefaultButton(QMessageBox::Save);/** 設置默認按鈕 **/
    msgBox.setIcon(QMessageBox::Warning);/** 設置圖標 **/
    int ret = msgBox.exec();/** 返回點擊的按鈕對應的整型值 **/
    switch(ret){
    case QMessageBox::Save:
        qDebug()<<QString::fromLocal8Bit("點擊了保存按鈕");
        break;
    case QMessageBox::Discard:
        qDebug()<<QString::fromLocal8Bit("點擊了不保存按鈕");
        break;
    case QMessageBox::Cancel:
        qDebug()<<QString::fromLocal8Bit("點擊了取消按鈕");
        break;
    default:
        qDebug()<<"error!";
    }
    /** 結束 **/

    QMessageBox::warning(this,"Warning Message!!!","Becaful with the gap!!");/** 使用靜態API創建一個QMessageBox **/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM