QT5入门之6 - Qt提示对话框

QT 提示对话框类型很多,有提示、警告、错误、询问、关于等。

最简单的: QMessageBox::warning (this,tr(“提示信息”),tr(“数据超范围。”));

void about ( QWidget * parent, const QString & title, const QString & text )
StandardButton critical ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton question ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )
StandardButton warning ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton )

参数都差不多,第一个参数是父窗口,第二个参数是标题,第三个参数是提示信息,第四个参数是提示按钮类型(有默认参数),第五个参数是默认的按钮。

QMessageBox::StandardButton reply;  
reply = QMessageBox::question(this, tr("QMessageBox::question()"),  
                                    MESSAGE,  
                                    QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);  
if (reply == QMessageBox::Yes)  
    questionLabel->setText(tr("Yes"));  
else if (reply == QMessageBox::No)  
    questionLabel->setText(tr("No"));  
else  
    questionLabel->setText(tr("Cancel"));  
     QMessageBox::warning(NULL, "warning", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
    QMessageBox::information(NULL, "warning", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
QMessageBox::about(NULL, "提示", "串口没有打开!");

你可能感兴趣的:(QT)