【问题标题】:Window and system tray icon does not appear when referenced from resources从资源中引用时不显示窗口和系统托盘图标
【发布时间】:2011-09-18 06:54:33
【问题描述】:

这是 testTray.py

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

import imgAgent_rc

class Window(QDialog):
    def __init__(self):
        super(Window, self).__init__()

        self.trayIcon = QSystemTrayIcon(self)

        icon = QIcon(':/images/logo/image_16x16.png')     # Problem
        #icon = QIcon('images/logo/image_16x16.png')        # OK

        self.trayIcon.setIcon(icon)
        self.trayIcon.setVisible(True)
        self.trayIcon.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

这是目录结构:

imgAgent.qrc
imgAgent_rc.py
testTray.py
+images
|---+logo
    |---image_16x16.png

imgAgent.prc

<RCC>
  <qresource prefix="logo">
    <file>images/logo/image_16x16.png</file>
    ...
  </qresource>
</RCC>

我使用以下代码生成了 .py 资源文件:
pyrcc4.exe -py3 -o imgAgent_rc.py imgAgent.qrc

系统托盘图标和窗口图标从资源引用时不会出现,但在相对路径引用时正常显示。

【问题讨论】:

  • 你能发布imgAgent.qrc吗,因为我认为你在qrc文件中为图标设置的路径与/images/logo/image_16x16.png不同。
  • 是的,对不起,我忘记了最重要的事情。我贴出来了

标签: python resources python-3.x pyqt


【解决方案1】:

试试这个资源文件代码:

<RCC>
  <qresource>
    <file>images/logo/image_16x16.png</file>
  </qresource>
</RCC>

【讨论】:

  • 抱歉,我忘记发布我的 .qrc 文件了。图片在那里。
  • 你是对的。我不小心使用了前缀 =“logo”。我尝试了 icon = QIcon(':/logo/images/logo/image_16x16.png') 并且工作了。我的错误,在我的眼前:-P
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-31
  • 2012-08-14
  • 2016-02-20
  • 1970-01-01
相关资源
最近更新 更多