5

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?

1 Answer 1

5

Try this:

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

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.