QMessageBox::Ok,QMessageBox::NoButton为什么仍然会显示出ok按钮
时间: 2023-12-04 14:38:07 浏览: 23
QMessageBox::Ok是系统提供的默认按钮之一,它代表了“确定”或“OK”的含义。而QMessageBox::NoButton则代表没有按钮被选中。当使用QMessageBox::information等函数时,如果没有指定自定义按钮,系统会默认显示一个OK按钮,因此即使没有显式指定OK按钮,它仍然会被显示出来。
相关问题
QMessageBox::Ok,QMessageBox::NoButton
QMessageBox::Ok和QMessageBox::NoButton都是Qt中QMessageBox类的按钮类型之一。其中,QMessageBox::Ok表示消息框中只有一个“确定”按钮,而QMessageBox::NoButton则表示消息框中没有按钮。通常情况下,我们会在QMessageBox中使用更多的按钮类型,例如QMessageBox::Yes、QMessageBox::No、QMessageBox::Cancel等,以便用户可以根据需要进行选择。
QMessageBox::question设置了QMessageBox::Close如何让close按钮不显示
要让QMessageBox的Close按钮不显示,可以通过设置QMessageBox的按钮属性来实现。具体步骤如下:
1. 创建一个QMessageBox对象,并设置其消息文本和图标。
2. 使用setStandardButtons()方法设置消息框的标准按钮。
3. 使用button()方法获取消息框的按钮。
4. 使用setButton()方法将Close按钮设置为不可见。
下面是示例代码:
```cpp
QMessageBox msgBox;
msgBox.setText("Are you sure you want to close?");
msgBox.setIcon(QMessageBox::Question);
// 设置标准按钮,包括Close按钮
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Close);
// 获取Close按钮
QAbstractButton* closeButton = msgBox.button(QMessageBox::Close);
// 设置Close按钮不可见
closeButton->setVisible(false);
// 显示消息框
msgBox.exec();
```
这样,通过将Close按钮设置为不可见,就可以实现在QMessageBox中隐藏Close按钮。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)