4

I try to get a list of all fields - only they one which are not hidden - from QqsVectorLayer in QGIS 3 using python API. In QGIS 2 I used to do it like that:

conf = layer.editFormConfig()
for field in layer.fields():
    if conf.widgetType(field.name()) != 'Hidden':
        print(field.alias())

What's the proper way to do that in QGIS 3?

5

Try this:

for index in layer.attributeList():
    if layer.editorWidgetSetup(index).type() != 'Hidden':
        print(layer.attributeDisplayName(index))
  • Thanks! Any way to get (in addition to the alias or displayName) the field name from the same loop? – geraldo Sep 24 '18 at 13:33
  • Yeap, you can use layer.fields()[index].name() inside that loop. – Germán Carrillo Sep 24 '18 at 14:02

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.