gpt4 book ai didi

c++ - 为 QMessageBox 设置父级

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:08:15 26 4
gpt4 key购买 nike

我不明白为 QMessageBox 设置父级有什么好处,例如在下面的代码中:

void mainWindow::showMessage(QString msg) {
QMesageBox::information(this, "title", msg); //'this' is parent
}

有人可以帮帮我吗?

最佳答案

可能是一些事情。首先QMessageBox继承自QDialog。由于 QDialog 具有父级概念,因此 QMessageBox 也应该保持一致。

具体来说,文档说:

parent is passed to the QDialog constructor.

至少,新对话框通常显示在其父对话框的顶部。

但是,还有更多!

根据文档,它可以实际影响功能。例如:

On Mac OS X, if you want your message box to appear as a Qt::Sheet of its parent, set the message box's window modality to Qt::WindowModal or use open(). Otherwise, the message box will be a standard dialog.

另外还有一个“Window Modality”和“Application Modality”的概念,前者只阻止父窗口的输入,后者阻止整个应用程序的输入。这显然需要知道 parent 的概念。

最后,对于某些 static 函数,例如 ::about(...),它寻找要使用的图标的第一个地方是 parent->图标()

因此,如果您想获得良好的特定于平台的行为并让您的代码跨平台,您最好将一个正常的父级传递给它。

关于c++ - 为 QMessageBox 设置父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6754049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com