Is there a way to add a combobox to a toolbar for QGIS? So far I can only find examples that add buttons.

I found this tutorial which seems to explain how to do this with general PyQT but haven't had any luck at all doing this with QGIS. So any help or guidance would be greatly appreciated.


I have achieved it by adding the following to the initGui method of my main python file.

self.toolBar = self.iface.addToolBar("My Toolbar")
self.toolBar.setObjectName("My Toolbar")

self.projCombo = QComboBox(self.iface.mainWindow())
self.projCombo.addItem('item 1')
self.projComboAction = self.toolBar.addWidget(self.projCombo)
self.projCombo.setToolTip("My Combo Box")
| improve this answer | |
  • Literally just reading a tutorial on the addWidget function. Exactly what I needed and works fine. Thank you very much – Dan Feb 6 '13 at 14:39
  • @James S Thanks to your answer, I've managed to add a list of my layers to the combo box. Strange thing is, the combo box isn't populated unless I reload the plugin. Any ideas? gis.stackexchange.com/questions/93230/… – user25976 Apr 22 '14 at 18:09

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.