19

I've been writing a QGIS plugin (using the "Plugin Builder" plugin), and decided I wanted to change the icon (icon.png).

After running make deploy to rebuild the plugin locally, the new icon appears in the Plugin Manager (both in the list of plugins, and the plugin description panel). So far, so good.

However, the old icon persists in the menu, and toolbar icons.

I've established that the icon.png is correct in the metadata.txt, and is getting copied into my ~/.qgis/python/plugins/myplugin directory.

This is especially puzzling - I'm not replacing the default plugin icon, but an icon I previously created to replace the default plugin icon. So this has worked before... :/

I've tried these...

  • restarting QGIS
  • uninstall, then reinstall plugin using plugin manager
  • destroy the plugin using make derase followed by make deploy
  • reload the plugin using the "Plugin reloader" plugin

Does QGIS cache icons somewhere? That's the only explanation I can think of. If it does, is there any way to flush the cache?

I'm using QGIS 2.10.1 Pisa on Ubuntu 14.04. I'm using "Plugin Builder" version 2.8.3

I suspect it won't be a problem for anyone who hasn't installed the plugin before, but it's a bit strange.

4 Answers 4

44

In QGIS 3, one needs to do

pyrcc5 -o resources.py resources.qrc 

Original answer, valid for QGIS2:

Your plugin icon was converted to a byte array and saved in resources.py

So if you want to change this icon you have to compile your resources again:

pyrcc4 -o resources.py resources.qrc 
5
  • 1
    after following your advice, and restarting QGIS, the icon has changed.. thank you!
    – Steven Kay
    Sep 12, 2015 at 23:04
  • 3
    .. and if that doesn't work, make clean followed by make deploy will remove the compiled resource and force the icon to be rebuilt
    – Steven Kay
    Oct 8, 2015 at 11:25
  • This gives me invalid syntax.
    – Sunny Naik
    Jun 7, 2017 at 8:26
  • 1
    Why do you use pyrcc5 in the first command, and version 4 in the second?
    – Pieter
    Dec 21, 2021 at 20:37
  • The first command worked for me, not the 2nd one.
    – juminet
    Mar 10, 2023 at 8:43
3

I had a similar problem, using QGIS Brighton 2.6.1 . I followed your intructions/tips and the solutions was:

  • Open OSGeo4W Shell and change to the plugin folder MyPlugin by typing: cd C:\Program Files\QGIS Brighton\apps\qgis\python\plugins\MyPlugin

  • Type: make clean (removes the resource_rc.py)

  • Type: make deploy (from resouce.qrc outputs new resource_rc.py)
  • In QGIS plugin manager, disable and re-enable the plugin (outputs new compiled resource_rc.pyc) And the new pictures/logos changed.

Thanks!

1
  • 1
    if you dont have "make" then just run "pyrcc5 -o resources.py resources.qrc" (QGIS 3)
    – sys49152
    Jan 20 at 11:11
2

I had some issue with this as well but solved it with changing the icon_path in the initGui function in my main script: icon_path = f'{self.plugin_dir}/icon.png' (from icon_path = ':/plugins/plugin_name/icon.png')

1

In addition to dmh126's answer make sure you haven't accidentally deleted the import and thus prevented the resources python code from compiling. E.g. if your resources file is 'resources.py' -- assuming python files aren't nested -- you would search your project to make sure your code has the line:

import resources

Alternatively, you can delete resources.pyc and reload the plugin to ensure it is indeed getting compiled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.