QMessageBox::StandardButton reply;不显示QMessageBox的标题图
时间: 2023-12-04 20:38:21 浏览: 38
QMessageBox::StandardButton reply是一个枚举类型的变量,用于存储用户在QMessageBox中点击的标准按钮。这些标准按钮包括Yes、No、Cancel、Ok等。如果你不想在QMessageBox中显示标题图标,可以使用QMessageBox::NoIcon作为QMessageBox::information()函数的第一个参数。例如:QMessageBox::information(NULL, "Title", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::NoIcon);。
相关问题
QMessageBox::question 显示到固定位置
QMessageBox::question 是 Qt 框架中用于显示询问对话框的函数。它本身并没有提供直接控制对话框位置的方法,但您可以通过以下步骤将其移动到指定的位置:
1. 获取 QMessageBox 对话框的窗口句柄,可以通过 QMessageBox::winId() 方法获取。
2. 创建一个 QWindow 对象并将其作为 QWidget 的子类,然后使用 QWindow::fromWinId() 方法将其与 QMessageBox 对话框关联。
3. 调用 QWidget::move() 方法移动 QMessageBox 对话框到指定位置。
下面是一个示例代码片段,可以将 QMessageBox::question 对话框移动到屏幕上的 (100, 100) 位置:
```cpp
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Question", "Do you want to proceed?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
// 用户选择了“是”
} else {
// 用户选择了“否”
}
// 获取 QMessageBox 对话框的窗口句柄
WId msgBoxId = QMessageBox::activeWindow()->winId();
// 创建一个 QWindow 对象并关联
QWindow* window = QWindow::fromWinId(msgBoxId);
QWidget* widget = QWidget::createWindowContainer(window, this);
// 移动对话框到指定位置
widget->move(100, 100);
```
需要注意的是,这种方法可能会影响到对话框的可移植性和可维护性,因此建议谨慎使用。
QMessageBox::question 显示的时候如何减少重绘过程
在显示 QMessageBox::question 对话框时,可以通过设置 QWidget::setAttribute(Qt::WA_DontShowOnScreen) 属性来减少重绘过程。这个属性告诉 Qt 框架不将对话框显示在屏幕上,直到您显式调用 QWidget::show() 方法来显示它。
下面是一个示例代码片段,演示如何设置 QWidget::setAttribute(Qt::WA_DontShowOnScreen) 属性来减少 QMessageBox::question 对话框的重绘过程:
```cpp
// 设置不显示在屏幕上
QMessageBox::StandardButton reply;
QMessageBox msgBox(QMessageBox::Question, "Question", "Do you want to proceed?",
QMessageBox::Yes|QMessageBox::No, this, Qt::Dialog | Qt::FramelessWindowHint);
msgBox.setAttribute(Qt::WA_DontShowOnScreen);
reply = msgBox.exec();
// 显示对话框并将其移动到指定位置
QWidget* widget = msgBox.parentWidget();
widget->move(100, 100);
widget->show();
```
这样做的好处是可以减少对话框的重绘次数,提高应用程序的性能和响应速度。但是需要注意,由于对话框没有实际显示在屏幕上,可能需要手动调整它的位置和大小。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)