QT Qmessagebox 与 bottonBox 结合应用例子

Qmessagebox最常见的用法就是矫正用户的误操作,提供正确的引导指示。

获取点击事件

首先,创建一个dialog之后会默认带一个控件QDialogButtonBox。

这里写图片描述

 if(ui->buttonBox->button(QDialogButtonBox::Ok)  == button)   //判断按下的是否为"确定”按钮

来进行控件交互获取点击OK(botton)事件。

void mainWindow::on_buttonBox_accepted()

当然也可以获得点击OK事件。

bottonBox控件槽函数

void mainWindow::on_buttonbox_clicked(QAbstractButton *button)
{
}

来获取全部的点击事件,其中

ui->buttonBox->button(QDialogButtonBox::OK);
ui->buttonBox->button(QDialogButtonBox::Cancel);
ui->buttonBox->button(QDialogButtonBox::Help);
ui->buttonBox->button(QDialogButtonBox::Save);

来区分到底是那一个点击按钮的点击事件。


最常见的用法是让用户输入不为空:

这里写图片描述
先判断lineEdit

QString str2 = ui->lineEdit_2->text();
  if(str2.isEmpty()){
  }

当用户完成输入却没有发现有空值的时候,先进入OK点击事件判断,然后通过弹窗消息提示用户。

QMessageBox::about(NULL, "警告", "经度不能为空");

QMessageBox函数

当然了,QMessageBox还有

QMessageBox::critical(NULL, "critical", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

QMessageBox::warning(NULL, "warning", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

QMessageBox::question(NULL, "question", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

QMessageBox::about(NULL, "About", "About this application");

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值