3

I have built a processing plugin which shows up in the QGIS Processing Toolbox. However, I am struggling trying to change the icon. Usually I do:

pyrcc5 -o resources.py resources.qrc

and it updates perfectly.

However, I do not have a

resources.py

file so I cannot adopt this approach. Is there another way to update it?

7
  • 2
    You may want to look at this answer for another approach that uses an icon file directly instead of using qrc file. So that you don't need to use pyrcc5 and to generate resource.py file. Commented Dec 22, 2020 at 10:41
  • I tried that but it doesnt seem to work either. Thanks Commented Dec 22, 2020 at 11:23
  • It should work. How did you try? Commented Dec 22, 2020 at 13:32
  • You said "it updates perfectly". What I understand is "it creates resources.py successfully". If not so, what do you mean by "it updates perfectly"? Commented Dec 22, 2020 at 13:35
  • I'm confused - where did I say that? I don't have a "resources.py" for this plugin Commented Dec 22, 2020 at 13:41

1 Answer 1

4

I was also looking for a way to do this too and found out the way. The command

pyrcc5 -o resources.py resources.qrc

will generate resources.py using the resources.qrc is input.

To change your icon:

  1. create the file resources.qrc with content like this:
<RCC>
    <qresource prefix="/plugins/your_plugin" >
        <file>logo.svg</file>
    </qresource>
</RCC>

  1. Make sure logo.svg or your icon is in the root directory of your plugin.

  2. Run: pyrcc5 -o resources.py resources.qrc

To reiterate, resources.py does not exist before you run this command. resources.py will be generated after this command.

  1. Import resources.py in your script and call for the icon:
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsProcessingProvider
from . import resources

class YourAlgorithmProvider(QgsProcessingProvider):
    # some class definitions here
    def icon(self):
        return QIcon(':/plugins/your_plugin/logo.svg')

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.