Search code examples
pythoniconspyqt4system-tray

icons in PyQt not showing properly


I have developed an app with system Tray having menu in Python 2.6.4 and PyQt4.

Every client system has python installed locally, and accessing PyQt4 from network location.

I set SystemTray and required icons for menu items as below. App folder has icons folder from where i am using. so i used os.getcwd()

i kept this app folder in a network so that everyone can access.

self.mnuItem_1 = QtGui.QAction(QtGui.QIcon(r'%s\icons\icon1.ico' % (os.getcwd())), "Menu Item 1", self)
self.mnuItem_2 = QtGui.QAction(QtGui.QIcon(r'%s\icons\icon1.ico' % (os.getcwd())), "Menu Item 1", self)

self.trayIconMenu = QtGui.QMenu(self)
self.trayIconMenu.addAction(self.mnuItem_1)
self.trayIconMenu.addAction(self.mnuItem_2)
self.trayIcon = QtGui.QSystemTrayIcon(self)
self.trayIcon.setContextMenu(self.trayIconMenu)
TrayIcon = (r'%s\ShowTime_Addons\Media\showtimeIcon.ico' % (os.getcwd()))
self.trayIcon.setIcon(QtGui.QIcon(TrayIcon))
self.trayIcon.setToolTip('Showtime')
self.trayIcon.show()

In some systems i could able to see the icons, but in some systems icons are not shown.

For testing i placed .png and used and it worked.

self.mnuItem_1 = QtGui.QAction(QtGui.QIcon(r'%s\icons\icon1.png' % (os.getcwd())), "Menu Item 1", self)
self.mnuItem_2 = QtGui.QAction(QtGui.QIcon(r'%s\icons\icon1.png' % (os.getcwd())), "Menu Item 1", self)

So came to an understanding that the issue is not with the path but something else.


Solution

  • I found out a solution for this scenario

    One approach is to set the paths in qt.config file and place this in the location of your executable.(In my case its C:\Python26)

    As i discribed in my Question that i am accessing PyQt4 from Network Location say \\somesystem\Share\PyQt4

    We will find a qt.config file in \\somesystem\Share\PyQt4 Take it and put this below lines in qt.conf

    [Paths]
    Prefix = //somesystem/Share/PyQt4
    Binaries = //somesystem/Share/PyQt4
    

    Everything works fine, even sqldrivers will be loaded. No Need of using app.addLibraryPath