3

I've made a few customised plugins using Plugin Builder and QT. They're all up and running, but I'm having some trouble changing the icon picture on the buttons that I've added to the toolbars to run my plugins.

Is there a way to insert my own picture in the button, or even have text instead? The only pic that seems to work is the default icon.png created by the Plugin Builder. I've tried changing the path in the python script (see below) but no avail, it only works with icon.png. Does a new picture have to be a certain size or type?

def initGui(self):
    """Create the menu entries and toolbar icons inside the QGIS GUI."""

    icon_path = ':/plugins/button/icon.png'
    self.add_action(
        icon_path,
        text=self.tr(u'button'),
        callback=self.run,
        parent=self.iface.mainWindow())
4

You have to add any external resources including the icons in the resources.qrc file.

resources.qrc = The .xml document created by Qt Designer. Contains relative paths to resources of the forms.
http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/plugins.html

resources.qrc format:
button/icon.png

http://doc.qt.io/qt-4.8/resources.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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