I want to add a new feature with the Add Feature button in the Attribute Table using one line of PyQGIS.

enter image description here

I can show the attribute table via


Is there not a method like iface.showAttributeTable(iface.activeLayer()).addFeature available?

EDIT: The table I'm adding features to has optional geometry. When geometry is needed directly in the table, the standard Add Feature from the Edit menu works fine: the feature is digitized in and then the attribute edit dialog comes up. But in other cases the geometry is going to be referenced from another table, so I want the attribute edit dialog to come up first, as happens when the Add feature button is selected from a showAttributeTable call.


I think you are looking for the QgisInterface.openFeatureForm() function where you could load it using:

iface.openFeatureForm(iface.activeLayer(), QgsFeature(), False)
  • 1
    That's it, thanks very much Joseph. Now my challenge is to open the specific .ui form that I have generated. But your answer gets me much further along! – Rudy Stricklan Feb 14 at 17:13
  • @RudyStricklan - Most welcome! Glad it helped :) – Joseph Feb 15 at 10:51

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.