More

Adding a PyQGIS Plugin to the Database Menu


I am developing a plugin which I would like to add to the Database menu instead of the default Plugins menu.

According to the PyQGIS Developer Cookbook all I have to do is add

category=Database

to my plugin's metadata.txt.

However, that does not have any effect. Do I have to add something in my initGui as well?

Currently the initGui looks like this:

def initGui(self): self.importCSV_action = QAction('Import CSV', self.iface.mainWindow()) QtCore.QObject.connect(self.importCSV_action, QtCore.SIGNAL("activated()"),self.importCSV) self.iface.addPluginToMenu('xxx', self.importCSV_action)

If I leave the category=Database out in my metadata.txt the plugin appears as expected in the Plugins menu.


The category entry in the metadata.txt is only minded as a tip for the plugin user. From the pyqgis developer cookbook: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/plugins.html

A corresponding “category” metadata entry exists to specify that, so the plugin can be classified accordingly. This metadata entry is used as tip for users and tells them where (in which menu) the plugin can be found. Allowed values for “category” are: Vector, Raster, Database or Web. For example, if your plugin will be available from Raster menu, add this to metadata.txt

If you use the latest Plugin Builder tool the code:

self.iface.addPluginToMenu(self.menu,action)

Should be:

self.iface.addPluginToDatabaseMenu(self.menu,action)

Or in your case:

self.iface.addPluginToDatabaseMenu('xxx', self.importCSV_action)


Watch the video: QGIS Python PyQGIS - Add layer to a map layout (October 2021).