QMessageBox设置按钮显示内容
时间: 2024-01-07 22:22:58 浏览: 46
以下是两种设置QMessageBox按钮显示内容的方法:
方法一:
```cpp
QMessageBox box(QMessageBox::Question, "标题", "弹出框按钮更改为中文!");
box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
box.setButtonText(QMessageBox::Ok, QString("确 定"));
box.setButtonText(QMessageBox::Cancel, QString("取 消"));
int ret1 = box.exec();
switch (ret1) {
case QMessageBox::Ok:
qDebug() << "1";
break;
case QMessageBox::Cancel:
qDebug() << "2";
break;
}
```
方法二:
```cpp
QMessageBox mess(QMessageBox::Question, "删除提示", "确认删除所选组件?", NULL);
QPushButton *okButton = mess.addButton(tr("确定"), QMessageBox::AcceptRole);
QPushButton *cancelButton = mess.addButton(tr("取消"), QMessageBox::RejectRole);
mess.exec();
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)