在 QDialog 上调用 activateWindow 将窗口发送到后台

发布于 2024-08-31 07:49:37 字数 734 浏览 4 评论 0原文

我正在调试用 C++/Qt4 编写的某些应用程序。在 Linux 上,某些窗口管理器(gnome-wm/metacity)存在问题,主窗口(基于 QDialog)是在后台创建的(不会引发)。我设法使用 PyQt4 和以下代码重新创建场景:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class PinDialog(QDialog):

    def showEvent(self, event):
        QDialog.showEvent(self, event)
        self.raise_()
        self.activateWindow()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = PinDialog()
    app.setActiveWindow(widget)
    widget.exec_()
    sys.exit(0)

如果我删除

self.activateWindow() 

应用程序,则按预期工作。这似乎是错误的,因为 activateWindow 的文档 没有指定任何可能发生类似情况的条件。

我的问题是: 是否有任何理由首先在 showEvent 中设置 activateWindow ?如果有某种原因,那么解决重点问题的好方法是什么?

I am debugging certain application written with C++/Qt4. On Linux it has problems that with certain window managers (gnome-wm/metacity), the main window (based on QDialog) is created in the background (it's not raised). I managed to re-create the scenario using PyQt4 and following code:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys

class PinDialog(QDialog):

    def showEvent(self, event):
        QDialog.showEvent(self, event)
        self.raise_()
        self.activateWindow()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = PinDialog()
    app.setActiveWindow(widget)
    widget.exec_()
    sys.exit(0)

If I remove

self.activateWindow() 

the application works as expected. This seems wrong, since documentation for activateWindow
does not specify any conditions under which something like this could happen.

My question is:
Is there any reason to have activateWindow in showEvent in the first place? If there is some reason, what would be good workaround for focusing issues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方圜几里 2024-09-07 07:49:37

我也见过这种行为。

根据文档

在 X11 上,结果取决于窗口管理器

看起来 Gnome 采取与 Microsoft Windows 相同的立场,不允许应用程序中断用户当前在另一个应用程序(在本例中为终端)中执行的操作。

I. too, have seen this behaviour.

According to the documentation:

On X11, the result depends on the Window Manager

It appears that Gnome is taking the same stance as Microsoft Windows in not allowing an application to interrupt what the user is currently doing in another application (in this case Terminal).

苦妄 2024-09-07 07:49:37

该问题很可能是由 Qt 中的错误引起的。我无法在最新的 Qt 版本中重现相同的行为。最初在 Fedora 13 上复制,Fedora 14 运行正常。

The problem was most probably caused by a bug in Qt. I can't reproduce the same behaviour in recent Qt versions. Originally reproduced on Fedora 13, Fedora 14 works OK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文