Class: QgsAttributeTableConfig

A container for configuration of the attribute table.

The configuration is specific for one vector layer.

Methods

actionWidgetStyle

Gets the style of the action widget

actionWidgetVisible

Returns True if the action widget is visible

columnHidden

Returns True if the specified column is hidden.

columnWidth

Returns the width of a column, or -1 if column should use default width.

columns

Gets the list with all columns and their configuration.

hasSameColumns

Compare this configuration's columns name, type, and order to other.

isEmpty

Returns True if the configuration is empty, ie it contains no columns.

mapVisibleColumnToIndex

Maps a visible column index to its original column index.

readXml

Deserialize to XML on layer load

setActionWidgetStyle

Set the style of the action widget

setActionWidgetVisible

Set if the action widget is visible

setColumnHidden

Sets whether the specified column should be hidden.

setColumnWidth

Sets the width of a column.

setColumns

Set the list of columns visible in the attribute table.

setSortExpression

Set the sort expression used for sorting.

setSortOrder

Set the sort order

size

Returns the number of columns in the configuration.

sortExpression

Gets the expression used for sorting.

sortOrder

Gets the sort order

update

Update the configuration with the given fields.

writeXml

Serialize to XML on layer save

Attributes

Action

ButtonList

DropDown

Field

class qgis.core.QgsAttributeTableConfig[source]

Bases: object

Action = 1
class ActionWidgetStyle

Bases: int

ButtonList = 0
class ColumnConfig

Bases: object

Defines the configuration of a column in the attribute table.

hidden: bool

Flag that controls if the column is hidden

name: str

The name of the attribute if this column represents a field

type: Type

The type of this column.

width: int

Width of column, or -1 for default width

DropDown = 1
Field = 0
class Type

Bases: int

actionWidgetStyle(self) QgsAttributeTableConfig.ActionWidgetStyle[source]

Gets the style of the action widget

Return type:

QgsAttributeTableConfig.ActionWidgetStyle

actionWidgetVisible(self) bool[source]

Returns True if the action widget is visible

Return type:

bool

columnHidden(self, column: int) bool[source]

Returns True if the specified column is hidden.

Parameters:

column (int) – column index

Raises:

IndexError – if the column is not found

Return type:

bool

columnWidth(self, column: int) int[source]

Returns the width of a column, or -1 if column should use default width.

Parameters:

column (int) – column index

Raises:

IndexError – if the column is not found

See also

setColumnWidth()

Return type:

int

columns(self) List[QgsAttributeTableConfig.ColumnConfig]

Gets the list with all columns and their configuration. The list order defines the order of appearance.

Return type:

List[QgsAttributeTableConfig.ColumnConfig]

hasSameColumns(self, other: QgsAttributeTableConfig) bool[source]

Compare this configuration’s columns name, type, and order to other. The column’s width is not considered.

Parameters:

other (QgsAttributeTableConfig)

Return type:

bool

isEmpty(self) bool[source]

Returns True if the configuration is empty, ie it contains no columns.

See also

size()

Return type:

bool

mapVisibleColumnToIndex(self, visibleColumn: int) int[source]

Maps a visible column index to its original column index.

Parameters:

visibleColumn (int) – index of visible column

Return type:

int

Returns:

corresponding index when hidden columns are considered

readXml(self, node: QDomNode)[source]

Deserialize to XML on layer load

Parameters:

node (QDomNode)

setActionWidgetStyle(self, actionWidgetStyle: QgsAttributeTableConfig.ActionWidgetStyle)[source]

Set the style of the action widget

Parameters:

actionWidgetStyle (QgsAttributeTableConfig.ActionWidgetStyle)

setActionWidgetVisible(self, visible: bool)[source]

Set if the action widget is visible

Parameters:

visible (bool)

setColumnHidden(self, column: int, hidden: bool)[source]

Sets whether the specified column should be hidden.

Parameters:
  • column (int) – column index

  • hidden (bool) – set to True to hide column

Raises:

IndexError – if the column is not found

See also

columnHidden()

setColumnWidth(self, column: int, width: int)[source]

Sets the width of a column.

Parameters:
  • column (int) – column index

  • width (int) – column width in pixels, or -1 if column should use default width

Raises:

IndexError – if the column is not found

See also

columnWidth()

setColumns(self, columns: Iterable[QgsAttributeTableConfig.ColumnConfig])[source]

Set the list of columns visible in the attribute table. The list order defines the order of appearance.

Parameters:

columns (Iterable[QgsAttributeTableConfig.ColumnConfig])

setSortExpression(self, sortExpression: str | None)[source]

Set the sort expression used for sorting.

Parameters:

sortExpression (Optional[str])

setSortOrder(self, sortOrder: Qt.SortOrder)[source]

Set the sort order

Parameters:

sortOrder (Qt.SortOrder)

size(self) int[source]

Returns the number of columns in the configuration.

Added in version 3.22.

Return type:

int

sortExpression(self) str[source]

Gets the expression used for sorting.

Return type:

str

sortOrder(self) Qt.SortOrder[source]

Gets the sort order

Return type:

Qt.SortOrder

update(self, fields: QgsFields)[source]

Update the configuration with the given fields. Any field which is present in the configuration but not present in the parameter fields will be removed. Any field which is in the parameter fields but not in the configuration will be appended.

Parameters:

fields (QgsFields)

writeXml(self, node: QDomNode)[source]

Serialize to XML on layer save

Parameters:

node (QDomNode)