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, "提示", "串口没有打开!");
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值