在 QDialog 上调用 activateWindow 将窗口发送到后台
我正在调试用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也见过这种行为。
根据文档:
看起来 Gnome 采取与 Microsoft Windows 相同的立场,不允许应用程序中断用户当前在另一个应用程序(在本例中为终端)中执行的操作。
I. too, have seen this behaviour.
According to the documentation:
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).
该问题很可能是由 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.