I have a combobox in my plugin (python Qt dockable widget) that needs to contain the currently open rasters.
How do I trigger an update of the plugin when something new gets added to the map?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
There's a couple of methods which I use (note that it may not be the most efficient solution):
(using Combo Box) - Add the following line before you populate your combo box:
Then when you add a new layer, close your plugin and open it again, the combo box should be re-populated with the new additions.
(using QgsMapLayerComboBox) - This is automatically updated when any changes are made to the layer list (i.e. layers added/removed, names changed etc) without you having to refresh the plugin. I would recommend this method. You can set it so that it only recognises raster layers by using something like:
self.dockwidget.mapLayerComboBox.setFilters( QgsMapLayerProxyModel.RasterLayer )
Note: When using QGIS custom widgets, you may need to edit your dockwidget_base.ui file, find the
QgsMapLayerComboBox class (usually at the end of the file) and replace the