2

I made a plugin what has multiple combobox but i have problem with the information load from the second combobox it depends on the combobox 1st. In the first combo box, i can choose layers from the loaded ones.

    layers = self.iface.legendInterface().layers()
    layer_list = []
    for layer in layers:
         layer_list.append(layer.name())

    self.dlg.reteg.addItems(layer_list)

And the problem is that, in the second combobox i want a list from the selected layer's attribute names.

1 Answer 1

2

Just play with the signal layerChanged from QgsMapLayerComboBox

Below, you will find a simple example to get layer id with layer.id() when you change layer in QgsMapLayerComboBox. You could instead use the setLayer slot from QgsFieldComboBox to set the attributes you want to display in your second combobox (assuming you have both combo components QgsMapLayerComboBox and QgsFieldComboBox)

def print_layer_id(layer):
    print layer.id()
# I supposed reteg is the id of the QgsMapLayerComboBox
self.dlg.reteg.layerChanged.connect(print_layer_id)
1
  • Sorry, this is my first plugin i created, and I'm on a very amateur lvl in this, i made a variable to read the layer name selected in the 'reteg' named combobox, and in layers it searching for the same name and select it, as active_vl, but the problem is, this is always be the first layer in the combobox list, after selecting an other the plugin dosn't refresh to the selected one. Commented Nov 1, 2015 at 15:58

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.