Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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")
share|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 at 18:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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