Context
I am developing a QGIS plugin using QGIS 3.22.11-Białowieża. One of the functions is to add a layer to the map and format the fields in the attributes form. I want to avoid developing a custom form and just use the "drag and drop designer" layout:
editFormConfig = feature_layer.editFormConfig()
editFormConfig.setLayout(1)
This is working great so far. I am able to customize my fields as needed and add them to the Attributes Form just fine, for example:
fields = feature_layer.fields()
field_index = fields.indexFromName(field_name)
widget_setup = QgsEditorWidgetSetup('TextEdit', {'IsMultiline': True, 'UseHtml': False})
feature_layer.setEditorWidgetSetup(field_index, widget_setup)
form_config = feature_layer.editFormConfig()
form_config.setLabelOnTop(field_index, True)
feature_layer.setEditFormConfig(form_config)
The Problem
I have a QgsAction
(button to open URL) that I would like to add to the Attributes Form.
helpAction = QgsAction(1, 'Open Help URL', help_action_text, None, capture=False, shortTitle='Help', actionScopes={'Layer'})
feature_layer.actions().addAction(helpAction)
This part is also working fine, the Action is added to the layer properly and is available as a widget in the drag-and-drop designer for the Attributes Form. When I manually drag the Action into the Form Layout, it appears as a button and works as expected.
However, I cannot find where to add this to the programmatically to the Attributes Form as I do with the fields. Is this even possible?
Question
How can I add a layer Action (QgsAction
) to that layer's Attributes Form programmatically?