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':

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


Try this:

for index in layer.attributeList():
    if layer.editorWidgetSetup(index).type() != 'Hidden':
  • 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. 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.