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.
This is the current result after using the "Identify Features""Identify Features" tool (Ctrl+Shift+I).
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)
Press Run script
and get the final output (again after using the "Identify Features""Identify Features" tool):
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:
References:




