Class: QgsLayoutItemAttributeTable¶
A layout table subclass that displays attributes from a vector layer.
Class Hierarchy¶
Base classes¶
Displays a table in the print layout, and allows the table to span over multiple frames. |
|
Abstract base class for layout items with the ability to distribute the content to several frames ( |
|
A base class for objects which belong to a layout. |
|
Abstract interface for generating an expression context. |
|
Interface for layout objects which support undo/redo commands. |
Abstract Methods
Queries the attribute table's vector layer for attributes to show in the table. |
Methods
Returns |
|
Returns the current expression used to filter features for the table. |
|
Returns |
|
Returns |
|
Returns the layout map whose extents are controlling the features shown in the table. |
|
Returns the maximum number of features to be shown by the table. |
|
Returns the relation id which the table displays child features from. |
|
Resets the attribute table's columns to match the vector layer's fields. |
|
Sets the attribute table to only show features which are visible in a map item. |
|
Sets the attributes to display in the table. |
|
Sets the expression used for filtering features in the table. |
|
Sets whether the feature filter is active for the attribute table. |
|
Sets attribute table to only show features which intersect the current atlas feature. |
|
Sets a layout map to use to limit the extent of features shown in the attribute table. |
|
Sets the maximum number of features shown by the table. |
|
Sets the relation id from which to display child features |
|
Sets the source for attributes to show in table body. |
|
Sets attribute table to only show unique rows. |
|
Sets whether the attribute table will be rendered using the conditional styling properties of the linked vector layer. |
|
Sets the vector layer from which to display feature attributes. |
|
Sets a string to wrap the contents of the table cells by. |
|
Returns the source for attributes shown in the table body. |
|
Returns the source layer for the table, considering the table source mode. |
|
Returns |
|
Returns |
|
Returns the vector layer the attribute table is currently using. |
|
Returns the string used to wrap the contents of the table cells by. |
Static Methods
Returns a new |
Attributes
- class qgis.core.QgsLayoutItemAttributeTable[source]¶
Bases:
QgsLayoutTable
- __init__(layout: QgsLayout | None)
Constructor for QgsLayoutItemAttributeTable, attached to the specified
layout
.Ownership is transferred to the layout.
- Parameters:
layout (Optional[QgsLayout])
- AtlasFeature = 1¶
- class ContentSource¶
Bases:
int
- LayerAttributes = 0¶
- RelationChildren = 2¶
- static create(layout: QgsLayout | None) QgsLayoutItemAttributeTable | None [source]¶
Returns a new
QgsLayoutItemAttributeTable
for the specified parentlayout
.- Parameters:
layout (Optional[QgsLayout])
- Return type:
Optional[QgsLayoutItemAttributeTable]
- displayOnlyVisibleFeatures(self) bool [source]¶
Returns
True
if the table is set to show only features visible on a corresponding map item.See also
See also
- Return type:
bool
- featureFilter(self) str [source]¶
Returns the current expression used to filter features for the table. The filter is only active if
filterFeatures()
isTrue
.See also
See also
- Return type:
str
- filterFeatures(self) bool [source]¶
Returns
True
if a feature filter is active on the attribute table.See also
See also
- Return type:
bool
- filterToAtlasFeature(self) bool [source]¶
Returns
True
if the table is set to only show features which intersect the current atlas feature.See also
- Return type:
bool
- abstract getTableContents(self, contents: Any) bool [source]¶
Queries the attribute table’s vector layer for attributes to show in the table.
- Parameters:
contents (Any) – table content
- Return type:
bool
- Returns:
True
if attributes were successfully fetched
- map(self) QgsLayoutItemMap | None [source]¶
Returns the layout map whose extents are controlling the features shown in the table. The extents of the map are only used if
displayOnlyVisibleFeatures()
isTrue
.See also
See also
- Return type:
Optional[QgsLayoutItemMap]
- maximumNumberOfFeatures(self) int [source]¶
Returns the maximum number of features to be shown by the table.
See also
- Return type:
int
- relationId(self) str [source]¶
Returns the relation id which the table displays child features from.
See also
See also
Note
Only used if table
source()
is set to RelationChildren.- Return type:
str
- resetColumns(self)[source]¶
Resets the attribute table’s columns to match the vector layer’s fields.
See also
- setDisplayOnlyVisibleFeatures(self, visibleOnly: bool)[source]¶
Sets the attribute table to only show features which are visible in a map item. Changing this setting forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.
See also
See also
- Parameters:
visibleOnly (bool)
- setDisplayedFields(self, fields: Iterable[str | None], refresh: bool = True)[source]¶
Sets the attributes to display in the table.
- Parameters:
fields (Iterable[Optional[str]]) – list of fields names from the vector layer to show. Set to an empty list to show all feature attributes.
refresh (bool = True) – set to
True
to force the table to refetch features from its vector layer and immediately update the display of the table. This may result in the table changing size to accommodate the new displayed feature attributes.
- setFeatureFilter(self, expression: str | None)[source]¶
Sets the
expression
used for filtering features in the table. The filter is only active iffilterFeatures()
is set toTrue
. Changing this setting forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.See also
See also
- Parameters:
expression (Optional[str])
- setFilterFeatures(self, filter: bool)[source]¶
Sets whether the feature filter is active for the attribute table. Changing this setting forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.
See also
See also
- Parameters:
filter (bool)
- setFilterToAtlasFeature(self, filterToAtlas: bool)[source]¶
Sets attribute table to only show features which intersect the current atlas feature.
See also
- Parameters:
filterToAtlas (bool)
- setMap(self, map: QgsLayoutItemMap | None)[source]¶
Sets a layout
map
to use to limit the extent of features shown in the attribute table. This setting only has an effect if setDisplayOnlyVisibleFeatures is set toTrue
. Changing the map forces the table to refetch features from its vector layer, and may result in the table changing size to accommodate the new displayed feature attributes.See also
See also
- Parameters:
map (Optional[QgsLayoutItemMap])
- setMaximumNumberOfFeatures(self, features: int)[source]¶
Sets the maximum number of
features
shown by the table. Changing this setting may result in the attribute table changing its size to accommodate the new number of rows, and requires the table to refetch features from its vector layer.See also
- Parameters:
features (int)
- setRelationId(self, id: str | None)[source]¶
Sets the relation
id
from which to display child featuresSee also
See also
Note
Only used if table
source()
is set to RelationChildren.- Parameters:
id (Optional[str])
- setSource(self, source: QgsLayoutItemAttributeTable.ContentSource)[source]¶
Sets the
source
for attributes to show in table body.See also
- Parameters:
- setUniqueRowsOnly(self, uniqueOnly: bool)[source]¶
Sets attribute table to only show unique rows.
Set
uniqueOnly
toTrue
to show only unique rows. Duplicate rows will be stripped from the table.See also
- Parameters:
uniqueOnly (bool)
- setUseConditionalStyling(self, enabled: bool)[source]¶
Sets whether the attribute table will be rendered using the conditional styling properties of the linked vector layer.
See also
Added in version 3.12.
- Parameters:
enabled (bool)
- setVectorLayer(self, layer: QgsVectorLayer | None)[source]¶
Sets the vector
layer
from which to display feature attributes.This is only considered if the table
source()
is LayerAttributes.See also
- Parameters:
layer (Optional[QgsVectorLayer])
- setWrapString(self, wrapString: str | None)[source]¶
Sets a string to wrap the contents of the table cells by. Occurrences of this string will be replaced by a line break.
- Parameters:
wrapString (Optional[str]) – string to replace with line break
See also
- source(self) QgsLayoutItemAttributeTable.ContentSource [source]¶
Returns the source for attributes shown in the table body.
See also
- Return type:
- sourceLayer(self) QgsVectorLayer | None [source]¶
Returns the source layer for the table, considering the table source mode. For example, if the table is set to atlas feature mode, then the source layer will be the atlas coverage layer. If the table is set to layer attributes mode, then the source layer will be the user specified vector layer.
- Return type:
Optional[QgsVectorLayer]
- uniqueRowsOnly(self) bool [source]¶
Returns
True
if the table is set to show only unique rows.See also
- Return type:
bool
- useConditionalStyling(self) bool [source]¶
Returns
True
if the attribute table will be rendered using the conditional styling properties of the linked vector layer.See also
Added in version 3.12.
- Return type:
bool
- vectorLayer(self) QgsVectorLayer | None [source]¶
Returns the vector layer the attribute table is currently using.
This is only considered if the table
source()
is LayerAttributes.See also
See also
- Return type:
Optional[QgsVectorLayer]