python - 如何让PyQT4窗口跳到最前面?

标签 python pyqt4

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

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

最佳答案

这个有效:

# 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 上都需要。

setWindowState 恢复最小化窗口并提供焦点。但是,如果窗口只是失去焦点而不是最小化,它就不会获得焦点。

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

同时使用两者具有预期的效果。

关于python - 如何让PyQT4窗口跳到最前面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12118939/

相关文章:

python - 在 Django Web 应用程序中保护 GET 请求

python - 在Python中更改Widget Window的样式和背景颜色

python - 具有可点击和可选择点的 PyQt4 散点图

Python - 在不使用 100% cpu 的情况下检查按键

python - "Chrome not reachable"在非 headless 模式下使用 Xvfb

python - PyQt QPushButton 背景颜色

python - Python 中的一个令人困惑的案例

python - 如何在 QLineEdit 中同时显示光标和 PlaceholderText?

python - RocksDB 可以处理多个只读客户端吗?

python - “QMainWindow”对象没有属性 'addWidget'