这是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
从资源引用时,系统托盘图标和窗口图标不会出现,但在相对路径引用时会正常显示。
答案 0 :(得分:2)
尝试使用此资源文件代码:
<RCC>
<qresource>
<file>images/logo/image_16x16.png</file>
</qresource>
</RCC>