I want to add multiple icons in the same file to display the plugins icons in the menu.
def initGui(self):
action = self.add_action( ':/plugins/Example/icons\icon1.png',
text=self.tr(u'Example'),
callback=self.ExampleMethod,
parent=self.iface.mainWindow(),
checkable=True,
toolbar=self.ExampleToolbar)
self.ExampleMethod = QgsMapTool(self.iface.mapCanvas())
self.ExampleMethod.setAction(action)
action = self.add_action( ':/plugins/Example/icons\icon2.png',
text=self.tr(u'Example1'),
callback=self.ExampleMethod1,
parent=self.iface.mainWindow(),
checkable=True,
toolbar=self.ExampleToolbar)
self.ExampleMethod1 = QgsMapTool(self.iface.mapCanvas())
self.ExampleMethod1.setAction(action)
but the problem is that the icons are not displaying.
I have used make clean
and make
commands and I have also updated the resources.qrc file.
What I have to do to display the icons in the menu?
Best Answer
You are mixing the two kinds of slash ("\" and "/") in your icon path. The escape sequence '\i' does not exist and it is interpreted as the simple character 'i'. For this reason the paths are not correct in:
and they are interpreted as:
and
respectively.
Try out this:
I hope this helps.