How can I hide a column in QGIS 3 using PyQGIS:

In QGIS 2 it was quite simple:

editFormConf = layer.editFormConfig()
idx = layer.fields().indexFromName(columnName)
editFormConf.setWidgetType(idx, "Hidden")

I investigated, and now in QGIS 3 it has changed to something like

idx = layer.fields().indexFromName(columnName)
editor_widget_setup = QgsEditorWidgetSetup(...)
layer.setEditorWidgetSetup(idx, editor_widget_setup)

The problem is the use of the constructor QgsEditorWidgetSetup(...)

How to tell the constructor that this field is hidden?

1 Answer 1


In QGIS 3 is necessary to use QgsEditorWidgetSetup in order to define the widget type and configuration for the field.

The following is minimal working example in Python Console which set a widget of type 'TextEdit' with MultiLine property set to True:

vl = iface.activeLayer()
idx = vl.fields().indexFromName('field')

setup = QgsEditorWidgetSetup('TextEdit', {'IsMultiline': 'True'})
vl.setEditorWidgetSetup(idx, setup)

So, to hide your column it is enough to do:

setup = QgsEditorWidgetSetup('Hidden', {})
vl.setEditorWidgetSetup(idx, setup)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.