【发布时间】: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