Skip to main content
added 44 characters in body
Source Link
Taras
  • 35.8k
  • 6
  • 77
  • 152

Here is a solution using PyQGIS solution.

Let's assume there is a polygon layer called 'test' with the following attribute table, see image below.

input

This is the current result after using the "Identify Features""Identify Features" tool (Ctrl+Shift+I).

identify_1

Proceed with Plugins > Python Console > Show Editor and paste the script below

# imports
from qgis.core import QgsProject, QgsEditorWidgetSetup

layer = QgsProject.instance().mapLayersByName("test")[0]
type = 'Hidden'
config = {'Layer':layer.id()}
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

indexsindexes = [layer.fields().indexOf(field) for field in not_required_fields]

for index in indexsindexes:
    field = layer.fields()[index]
    widget_setup = QgsEditorWidgetSetup(type, config)
    layer.setEditorWidgetSetup(index, widget_setup)

enter image description here

Press Run script run script and get the final output (again after using the "Identify Features""Identify Features" tool):

output_1

To exclude these fields from the attribute table use this piece of code:

# imports
from qgis.core import QgsProject

layer = QgsProject.instance().mapLayersByName("test")[0]
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

config = layer.attributeTableConfig()

columns = config.columns()

for column in columns:
    if column.name in not_required_fields:
        column.hidden = not False

config.setColumns(columns)
layer.setAttributeTableConfig(config)

So, the attribute table now will look like:

output_2


References:

Here is a solution using PyQGIS.

Let's assume there is a polygon layer called 'test' with the following attribute table, see image below.

input

This is the current result after using the "Identify Features" tool (Ctrl+Shift+I).

identify_1

Proceed with Plugins > Python Console > Show Editor and paste the script below

layer = QgsProject.instance().mapLayersByName("test")[0]
type = 'Hidden'
config = {'Layer':layer.id()}
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

indexs = [layer.fields().indexOf(field) for field in not_required_fields]

for index in indexs:
    field = layer.fields()[index]
    widget_setup = QgsEditorWidgetSetup(type, config)
    layer.setEditorWidgetSetup(index, widget_setup)

enter image description here

Press Run script run script and get the final output (again after using the "Identify Features" tool):

output_1

To exclude these fields from the attribute table use this piece of code:

layer = QgsProject.instance().mapLayersByName("test")[0]
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

config = layer.attributeTableConfig()

columns = config.columns()

for column in columns:
    if column.name in not_required_fields:
        column.hidden = not False

config.setColumns(columns)
layer.setAttributeTableConfig(config)

So, the attribute table now will look like

output_2


References:

Here is a PyQGIS solution.

Let's assume there is a polygon layer called 'test' with the following attribute table, see image below.

input

This is the current result after using the "Identify Features" tool (Ctrl+Shift+I).

identify_1

Proceed with Plugins > Python Console > Show Editor and paste the script below

# imports
from qgis.core import QgsProject, QgsEditorWidgetSetup

layer = QgsProject.instance().mapLayersByName("test")[0]
type = 'Hidden'
config = {'Layer':layer.id()}
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

indexes = [layer.fields().indexOf(field) for field in not_required_fields]

for index in indexes:
    field = layer.fields()[index]
    widget_setup = QgsEditorWidgetSetup(type, config)
    layer.setEditorWidgetSetup(index, widget_setup)

Press Run script run script and get the final output (again after using the "Identify Features" tool):

output_1

To exclude these fields from the attribute table use this piece of code:

# imports
from qgis.core import QgsProject

layer = QgsProject.instance().mapLayersByName("test")[0]
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

config = layer.attributeTableConfig()

columns = config.columns()

for column in columns:
    if column.name in not_required_fields:
        column.hidden = not False

config.setColumns(columns)
layer.setAttributeTableConfig(config)

So, the attribute table now will look like:

output_2


References:

added 852 characters in body
Source Link
Taras
  • 35.8k
  • 6
  • 77
  • 152

Here is a solution using some PyQGIS.

Let's assume there is a polygon layer called 'test' with the following attribute table, see image below.

input

This is the current result after using the "Identify Features" tool (Ctrl+Shift+I).

identify_1

Proceed with Plugins > Python Console > Show Editor and paste the script below

layer = QgsProject.instance().mapLayersByName("test")[0]
type = 'Hidden'
config = {'Layer':layer.id()}
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

indexs = [layer.fields().indexOf(field) for field in not_required_fields]

for index in indexs:
    field = layer.fields()[index]
    widget_setup = QgsEditorWidgetSetup(type, config)
    layer.setEditorWidgetSetup(index, widget_setup)

enter image description here

Press Run script run script and get the final output (again after using the "Identify Features" tool):

outputoutput_1

To exclude these fields from the attribute table use this piece of code:

layer = QgsProject.instance().mapLayersByName("test")[0]
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

config = layer.attributeTableConfig()

columns = config.columns()

for column in columns:
    if column.name in not_required_fields:
        column.hidden = not False

config.setColumns(columns)
layer.setAttributeTableConfig(config)

So, the attribute table now will look like

output_2


References:

Here is a solution using some PyQGIS.

Let's assume there is a polygon layer called 'test' with the following attribute table, see image below.

input

identify_1

Proceed with Plugins > Python Console > Show Editor and paste the script below

layer = QgsProject.instance().mapLayersByName("test")[0]
type = 'Hidden'
config = {'Layer':layer.id()}
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

indexs = [layer.fields().indexOf(field) for field in not_required_fields]

for index in indexs:
    field = layer.fields()[index]
    widget_setup = QgsEditorWidgetSetup(type, config)
    layer.setEditorWidgetSetup(index, widget_setup)

enter image description here

Press Run script run script and get the final output:

output

Here is a solution using PyQGIS.

Let's assume there is a polygon layer called 'test' with the following attribute table, see image below.

input

This is the current result after using the "Identify Features" tool (Ctrl+Shift+I).

identify_1

Proceed with Plugins > Python Console > Show Editor and paste the script below

layer = QgsProject.instance().mapLayersByName("test")[0]
type = 'Hidden'
config = {'Layer':layer.id()}
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

indexs = [layer.fields().indexOf(field) for field in not_required_fields]

for index in indexs:
    field = layer.fields()[index]
    widget_setup = QgsEditorWidgetSetup(type, config)
    layer.setEditorWidgetSetup(index, widget_setup)

enter image description here

Press Run script run script and get the final output (again after using the "Identify Features" tool):

output_1

To exclude these fields from the attribute table use this piece of code:

layer = QgsProject.instance().mapLayersByName("test")[0]
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

config = layer.attributeTableConfig()

columns = config.columns()

for column in columns:
    if column.name in not_required_fields:
        column.hidden = not False

config.setColumns(columns)
layer.setAttributeTableConfig(config)

So, the attribute table now will look like

output_2


References:

Source Link
Taras
  • 35.8k
  • 6
  • 77
  • 152

Here is a solution using some PyQGIS.

Let's assume there is a polygon layer called 'test' with the following attribute table, see image below.

input

identify_1

Proceed with Plugins > Python Console > Show Editor and paste the script below

layer = QgsProject.instance().mapLayersByName("test")[0]
type = 'Hidden'
config = {'Layer':layer.id()}
not_required_fields = ["pop06", "pop618", "pop1835", "pop3565", "pop6599"]

indexs = [layer.fields().indexOf(field) for field in not_required_fields]

for index in indexs:
    field = layer.fields()[index]
    widget_setup = QgsEditorWidgetSetup(type, config)
    layer.setEditorWidgetSetup(index, widget_setup)

enter image description here

Press Run script run script and get the final output:

output