PyQt4 最小化到托盘 [英] PyQt4 Minimize to Tray

查看:89
本文介绍了PyQt4 最小化到托盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 PyQt4 中最小化到托盘?我已经使用了 QSystemTrayIcon 类,但现在我想最小化或隐藏"我的应用程序窗口,并且只显示托盘图标.

Is there a way to minimize to tray in PyQt4? I've already worked with the QSystemTrayIcon class, but now I would like to minimize or "hide" my app window, and show only the tray icon.

有人做过吗?任何方向将不胜感激.

Has anybody done this? Any direction would be appreciated.

在 Window XP Pro 上使用 Python 2.5.4 和 PyQt4

Using Python 2.5.4 and PyQt4 on Window XP Pro

推荐答案

一旦你记住没有办法真正最小化到 系统托盘.

It's pretty straightforward once you remember that there's no way to actually minimize to the system tray.

相反,你通过这样做来伪造它:

Instead, you fake it by doing this:

  1. 捕捉窗口上的最小化事件
  2. 在最小化事件处理程序中,创建并显示一个 QSystemTrayIcon
  3. 同样在最小化事件处理程序中,在窗口上调用 hide() 或 setVisible(false)
  4. 在系统托盘图标上点击/双击/菜单项
  5. 在您的系统托盘图标事件处理程序中,在您的窗口上调用 show() 或 setVisible(true),并可选择隐藏您的托盘图标.

这篇关于PyQt4 最小化到托盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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