3

Using QGIS 2.14.1, I use the Layer Properties > Fields > Edit Widget to hide the display of an attribute in the attribute table, as shown in this screenshot:

enter image description here

Is it possible to hide multiple attributes all at once without the time-consuming process of going through the Edit Widget one field at a time?

4

You can do this via the python interface. Start the Python Console from the plugin menu.

As an example, this code will set all 10 fields of the first layer to "Hidden":

# get map canvas object
mc = iface.mapCanvas()

# get the first layer (layer 0)
l = mc.layers()[0]

# get the edit form configuration
f = l.editFormConfig()

# loop over 0 to 9, and set fields to "Hidden"

[f.setWidgetType(i, "Hidden") for i in range(10)]

# outputs: [None, None, None, None, None, None, None, None, None, None]

It should be possible to get the number of fields from the layer info somehow so you can replace the 10 with something that works with however many fields you have...

If you want to set some edit forms to "Hidden", then get the f as above and just do f.setWidgetType(3,"Hidden") to set the fourth (python starts at 0) field to Hidden. Repeat for all the fields you want.

  • Perfect! Thanks so much. I didn't know anything about Python before this question, and I learned a little by observing your code. I became curious about how to select the layer. I tried to select the second layer in the table of contents by changing – Stu Smith May 9 '16 at 5:25
  • l = mc.layers()[0] to l = mc.layers()[1], but none of the fields were changed to Hidden. Weird... – Stu Smith May 9 '16 at 5:31
0

It is not included in QGIS itself.

Note that "l = mc.layers()[0]" refers to the first layer that is visible (ticked in layers panel) - If you always leave the zero be in the script you can just tick/untick layers to make the relevant layer being the first visible and the run the script.

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.