4

I'm unable to setup the display of the toolbar icon for a plugin in QGIS 2.0. I have compiled the "resources.qrc" with the correct path and filename, and checked possible spelling errors in the code.

In fact, the icon is displayed in the plugin manager but not on the toolbar or the dropdown menu (?). The plugin has been started using the plugin builder for 1.8 version, but works just fine. The plugin folder is linked to the qgis plugins folder by a symlink on a linux system.

Thanks.

Edit: my qrc file :

<RCC>
    <qresource prefix="/plugins/ViewshedAnalysis" >
        <file>icon.png</file>
    </qresource>
</RCC>

and my code :

self.action = QAction(
        QIcon(":/plugins/ViewshedAnalysis/icon.png"),
        u"Viewshed", self.iface.mainWindow())
QObject.connect(self.action, SIGNAL("triggered()"), self.run)


# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(u"&Viewshed Analysis", self.action)
6
  • What do you see in the icons place? Nothing?
    – Nathan W
    Commented Dec 10, 2013 at 12:12
  • yes, it's empty
    – Zoran
    Commented Dec 10, 2013 at 13:06
  • Can you past your resources.qrc and and example of you loading the icon.
    – Nathan W
    Commented Dec 10, 2013 at 13:07
  • 2
    did you import your compiled resource? import resources_rc Commented Dec 11, 2013 at 9:10
  • 1
    Bingo! I do import the resources, but with a small typo ... so now it works perfectly! (I would never figure thos out :)
    – Zoran
    Commented Dec 12, 2013 at 13:26

1 Answer 1

3

Worked for myself as well, as Matthias suggested if you add the following to your import statements:

import resources_rc

It works as long as you have updated and recompiled your resources file:

pyrcc4 -o resources_rc.py resources.qrc

(In windows easiest to run with the OSGeo4W shell, cd to directory)

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