1

I want to select raster layers by a GUI, so I designed a form by Qt designer that can add raster layers in 5 combo boxes. I want when a user select first raster layer in first combo box, and then user wants to select next layer in second combo box, name of first layer don't show in second combo box to select and this continue for other combo boxes. my code is:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()

    # clear the combo box to list only current layers
    self.dlg.cBox_Exp_1.clear()
    self.dlg.cBox_Exp_2.clear()
    self.dlg.cBox_Exp_3.clear()
    self.dlg.cBox_Exp_4.clear()
    self.dlg.cBox_Sen_1.clear()
    self.dlg.cBox_Sen_2.clear()
    self.dlg.cBox_Capa_1.clear()
    self.dlg.cBox_Capa_2.clear()
    self.dlg.cBox_Capa_1.clear()
    self.dlg.linOutput.clear()

    # get the layers and add them to the combo box
    layers = QgsMapLayerRegistry.instance().mapLayers().values()
    for layer in layers:
        if layer.type() == QgsMapLayer.RasterLayer:
            self.dlg.cBox_Exp_1.addItem(layer.name(), layer)
            self.dlg.cBox_Exp_2.addItem(layer.name(), layer)
            self.dlg.cBox_Exp_3.addItem(layer.name(), layer)
            self.dlg.cBox_Exp_4.addItem(layer.name(), layer)
            self.dlg.cBox_Sen_1.addItem(layer.name(), layer)
            self.dlg.cBox_Sen_2.addItem(layer.name(), layer)
            self.dlg.cBox_Capa_1.addItem(layer.name(), layer)
            self.dlg.cBox_Capa_2.addItem(layer.name(), layer)
    # Run the dialog event loop
    result = self.dlg.exec_()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.