3

I want to invoke the builtin add field dialog from my python plugin in QGIS:

enter image description here

This is the add attribute dialog of the attribute table.

It is located HERE. I expect it to return a QgsField. Unfortunately qgis.app namespace does not exists which would seem the obvious location of it.

It would be nice to invoke it without layer attribute since I want to ensure the returned QgsField attribute for all of the selected layers instead of a single one.

2
+50

qgsaddattrdialog is not available in Python (try to make from qgis.gui import QgsAddAttrDialog to see it fails)

You should better inspect code from "Table Manager" plugin (done in Python).

Look in particular at tableManager_gui.py file to manage the UI to add/manage fields and use QgsField

For getting all QgsField from selected layers, do:

selected_layers = iface.layerTreeView().selectedLayers()

for layer in selected_layers:
    for field in layer.fields():
        print layer.name(), field.name()
  • Thanks, but I am looking for a positive answer. I prefer to stick to the main UI. As you can see Table Manager has its own different insert dialog. In fact most plugins do reinvent the weel by designing custom UIs for tasks that are already covered by the official UI. Probably I will take the .ui from the QGIS source and provide identical behavior by Python. But that is a workaround which I also won't accept as a solution. I can accept a ctypes solution though. – SzieberthAdam Jan 12 '16 at 9:29

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.