7

I work on and test more QGIS plugins which falls into the same category (lets call it MyProcessing). Though they fall into the same category I want to keep them as separate plugins. I would like to have these plugins in the Plugins menu sharing same menu item (My Processing) and especially sharing the same toolbar (separate from standard plugin toolbar). Is there a way to do that?

In one plugin I create toolbar in interface:

self.toolbar = self.iface.addToolBar(u'MyProcessing')
self.toolbar.setObjectName(u'MyProcessing')

How do I check in other plugin if toolbar MyProcessing exists and add icon into it?

Same with the menu item, is there a way to check if menu item already exists and add other plugin action into it?

1

1 Answer 1

11

Use the findChild method of QGIS mainWindow to know if there is a QToolBar called u'MyProcessing' and get it. If you don't get anything, create it.

myToolBar = iface.mainWindow().findChild( QToolBar, u'MyProcessing' )
if not myToolBar:
    myToolBar = iface.addToolBar( u'MyProcessing' )
    myToolBar.setObjectName( u'MyProcessing' )

This needs to be checked in each of your plugins. You can then use myToolBar to add actions and perhaps a separator to visually group actions (buttons) for each plugin:

myToolBar.addAction( 'A' )
myToolBar.addAction( 'B' )
myToolBar.addSeparator()
myToolBar.addAction( 'C' )

As you pointed out, reusing menus is explained here: Adding multiple plugins to custom menu in QGIS

1
  • 1
    Aha! So the only difference between finding item in menu and item in toolbar is using QToolBar or QMenu in findChild(). Thank you :)
    – Miro
    Commented Nov 11, 2016 at 2:38

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.