模态QMessageBox的行为不像本机Windows对话框 [英] Modal QMessageBox does not behave like native Windows dialogs

查看:65
本文介绍了模态QMessageBox的行为不像本机Windows对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序具有一个对话框,该对话框通过QMessageBox询问用户是要放弃他所做的所有更改还是要继续编辑.我希望此对话框对整个应用程序是模态的.

My application has a dialog that asks the user via a QMessageBox whether he wants to discard all changes he made or wants to keep editing. I want this dialog to be modal to the whole application.

我在某处读到这是QMessageBox的标准行为,因此我不必显式设置它,例如:

I read somewhere that this is the standard behavior for a QMessageBox, so I dont have to set it explicitly with something like:

mbox.setWindowModality(Qt::ApplicationModal);

我想知道为什么它的行为与操作系统中的其他模式对话框(在我的情况下为Windows 7)不同.一方面,它的功能与应有的功能相同,即,应用程序中的所有其他输入方法都将被阻止,直到用户回答对话框为止.但是,如果用户单击应用程序的任何其他窗口,它不会闪烁" *.有什么方法可以使Qt像本机Windows对话框一样起作用?

I wonder why it behaves differently from other modal dialogs in the OS (Windows 7 in my case). On the one hand it functions like it should, i.e. all other input methods in the application are blocked until the user answeres the dialog. However, it doesn't 'blink'* if the user clicks any other window of the application. Is there any way to get Qt to behave like a native Windows dialog?

提前谢谢!

* 如果您不知道我所说的闪烁"是什么:只需在Windows操作系统上打开记事本,键入一些文本并尝试将其关闭.弹出一个对话框,要求保存,丢弃或继续编辑.现在,单击编辑器窗口上的某处->对话框的边框和标题栏会闪烁几次.

推荐答案

当消息框没有父级时,就会出现此问题.这对我来说很好:

The problem arises when the message box has no parent. This works fine for me:

QMessageBox box(this);
box.setStandardButtons(QMessageBox::Close);
box.exec();

但这不是:

QMessageBox box;
box.setStandardButtons(QMessageBox::Close);
box.exec();

这很有道理...除非知道其父项已被单击,否则消息框不会闪烁.

This makes sense... the message box can't blink unless it knows that its parent was clicked on.

这篇关于模态QMessageBox的行为不像本机Windows对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆