3

How can I hide a column in qgis3 using pyqgis:

In Qgis2 it was quite simple:

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

I investigated, and now in Qgis3 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

3

In QGIS3 is necessary to use QgsEditorWidgetSetup in order to define the widget type and confguration 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, privacy policy and cookie policy

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