如何让 PyQT4 窗口跳到前面? [英] How to make a PyQT4 window jump to the front?

查看:49
本文介绍了如何让 PyQT4 窗口跳到前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个 PyQT4 窗口(QtGui.QMainWindow)在应用程序收到另一台机器的指定消息时跳到最前面.通常窗口被最小化.

I want to make a PyQT4 window(QtGui.QMainWindow) jump to the front when the application received a specified message from another machine. Usually the window is minimized.

我尝试了 raise_(​​)show() 方法,但它不起作用.

I tried the raise_() and show() method but it doesn't work.

推荐答案

这有效:

# this will remove minimized status 
# and restore window with keeping maximized/normal state
window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)

# this will activate the window
window.activateWindow()

我在 Win7 上两者都需要.

Both are required for me on Win7.

setWindowState 恢复最小化的窗口并提供焦点.但是,如果窗口刚刚失去焦点,而不是最小化的,它不会给焦点.

setWindowState restores the minimized window and gives focus. But if the window just lost focus and not minimized, it won't give focus.

activateWindow 提供焦点但不恢复最小化状态.

activateWindow gives focus but doesn't restore the minimized state.

两者兼用即可达到预期效果.

Using both has the desired effect.

这篇关于如何让 PyQT4 窗口跳到前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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