Class: QgsLayoutTable¶
- class qgis.core.QgsLayoutTable(layout: QgsLayout)¶
Bases:
QgsLayoutMultiFrame
Constructor for
QgsLayoutTable
, belonging to the specifiedlayout
.A class to display a table in the print layout, and allow the table to span over multiple frames
Methods
Returns the color used for the background of the table.
Calculates the maximum width of text shown in columns.
Calculates the maximum height of text shown in rows.
Returns the margin distance between cell borders and their contents in mm.
Returns the cell style for a cell
group
.Returns a reference to the list of
QgsLayoutTableColumns
shown in the tableReturns the conditional style to use for the cell at
row
,column
.Returns the font used to draw text in table body cells.
Returns the color used to draw text in table body cells.
Returns the format used to draw content text in the table.
Returns the current contents of the table.
Checks whether a table contents contains a given row
Draws the horizontal grid lines for the table.
Returns the behavior mode for empty tables.
Returns the message for empty tables with no content rows.
- param frameIndex
Fetches the contents used for the cells in the table.
Returns the color used for grid lines in the table.
Returns the width of grid lines in the table in mm.
Returns the font used to draw header text in the table.
Returns the color used to draw header text in the table.
Returns the horizontal alignment for table headers.
Returns the display mode for headers in the table.
Returns the format used to draw header text in the table.
Returns the horizontal alignment to use for the cell at the specified
row
andcolumn
.Returns whether the grid’s horizontal lines are drawn in the table.
- param frameIndex
Sets object properties from a DOM element
- param itemElem
Recalculates and updates the size of the table and all table frames.
Refreshes the contents shown in the table by querying for new data.
- param context
Calculates a range of rows which should be visible in a given frame.
Calculates how many content rows would be visible within a frame of the specified height.
Creates a new
QgsExpressionContextScope
for the cell atrow
,column
.Sets the
color
used for background of table.Sets the
margin
distance in mm between cell borders and their contents.Sets the cell
style
for a cellgroup
.Replaces the columns in the table with a specified list of
QgsLayoutTableColumns
.Sets the
font
used to draw text in table body cells.Sets the
color
used to draw text in table body cells.Sets the
format
used to draw content text in the table.Sets the behavior
mode
for empty tables with no content rows.Sets the
message
for empty tables with no content rows.Sets the
color
used for grid lines in the table.Sets the
width
in mm for grid lines in the table.Sets the
font
used to draw header text in the table.Sets the
color
used to draw header text in the table.Sets the horizontal
alignment
for table headers.Sets the display
mode
for headers in the table.Sets the
format
used to draw header text in the table.Sets whether the grid’s horizontal lines should be drawn in the table
Sets whether empty rows should be drawn.
Sets whether grid lines should be drawn in the table
Replaces the sorting columns in the table with a specified list of
QgsLayoutTableSortColumns
.Sets whether the grid’s vertical lines should be drawn in the table
Sets the wrap
behavior
for the table, which controls how text within cells is automatically wrapped.Returns whether empty rows are drawn in the table.
Returns whether grid lines are drawn in the table
Returns a reference to the list of
QgsLayoutTableSortColumns
shown in the tableReturns the text format to use for the cell at the specified
row
andcolumn
.Returns the text format to use for the header cell at the specified
column
.- rtype
float
- rtype
QSizeF
- rtype
float
Returns the vertical alignment to use for the cell at the specified
row
andcolumn
.Returns whether the grid’s vertical lines are drawn in the table.
Returns the wrap behavior for the table, which controls how text within cells is automatically wrapped.
Stores object properties within an XML DOM element.
- param elem
Attributes
- AllFrames = 1¶
- class CellStyleGroup¶
Bases:
int
- class EmptyTableMode¶
Bases:
int
- EvenColumns = 1¶
- EvenRows = 3¶
- FirstColumn = 4¶
- FirstFrame = 0¶
- FirstRow = 7¶
- FollowColumn = 0¶
- HeaderCenter = 2¶
- class HeaderHAlignment¶
Bases:
int
- HeaderLeft = 1¶
- class HeaderMode¶
Bases:
int
- HeaderRight = 3¶
- HeaderRow = 6¶
- HeadersOnly = 0¶
- HideTable = 1¶
- LastColumn = 5¶
- LastRow = 8¶
- NoHeaders = 2¶
- OddColumns = 0¶
- OddRows = 2¶
- ShowMessage = 2¶
- TruncateText = 0¶
- class WrapBehavior¶
Bases:
int
- WrapText = 1¶
- backgroundColor(self) → QColor¶
Returns the color used for the background of the table.
See also
See also
- Return type
QColor
- calculateMaxColumnWidths(self) → bool¶
Calculates the maximum width of text shown in columns.
- Return type
bool
- calculateMaxRowHeights(self) → bool¶
Calculates the maximum height of text shown in rows.
- Return type
bool
- cellMargin(self) → float¶
Returns the margin distance between cell borders and their contents in mm.
See also
- Return type
float
- cellStyle(self, group: QgsLayoutTable.CellStyleGroup) → QgsLayoutTableStyle¶
Returns the cell style for a cell
group
.See also
- Parameters
group (QgsLayoutTable.CellStyleGroup) –
- Return type
- childEvent(self, QChildEvent)¶
- columns(self) → List[QgsLayoutTableColumn]¶
Returns a reference to the list of
QgsLayoutTableColumns
shown in the tableSee also
- Return type
List[QgsLayoutTableColumn]
- conditionalCellStyle(self, row: int, column: int) → QgsConditionalStyle¶
Returns the conditional style to use for the cell at
row
,column
.New in version 3.12.
- Parameters
row (int) –
column (int) –
- Return type
- connectNotify(self, QMetaMethod)¶
- contentFont(self) → QFont¶
Returns the font used to draw text in table body cells.
See also
See also
Deprecated since version use:
contextTextFormat()
instead- Return type
QFont
- contentFontColor(self) → QColor¶
Returns the color used to draw text in table body cells.
See also
See also
See also
Deprecated since version use:
contextTextFormat()
instead- Return type
QColor
- contentTextFormat(self) → QgsTextFormat¶
Returns the format used to draw content text in the table.
See also
See also
New in version 3.16.
- Return type
- contents(self) → object¶
Returns the current contents of the table. Excludes header cells.
- Return type
object
- contentsContainsRow(self, contents: object, row: Iterable[Any]) → bool¶
Checks whether a table contents contains a given row
- Parameters
contents (object) – table contents to check
row (Iterable[Any]) – row to check for
- Return type
bool
- Returns
True
if contents contains rows
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- drawHorizontalGridLines(self, context: QgsLayoutItemRenderContext, firstRow: int, lastRow: int, drawHeaderLines: bool)¶
Draws the horizontal grid lines for the table.
- Parameters
context (QgsLayoutItemRenderContext) – destination render context
firstRow (int) – index corresponding to first row shown in frame
lastRow (int) – index corresponding to last row shown in frame. If greater than the number of content rows in the table, then the default row height will be used for the remaining rows.
drawHeaderLines (bool) – set to
True
to include for the table header
See also
drawVerticalGridLines()
- emptyTableBehavior(self) → QgsLayoutTable.EmptyTableMode¶
Returns the behavior mode for empty tables. This property controls how the table is drawn if it contains no content rows.
See also
- Return type
- emptyTableMessage(self) → str¶
Returns the message for empty tables with no content rows. This message is displayed in the table body if the empty table behavior is set to ShowMessage.
See also
See also
- Return type
str
- fixedFrameSize(self, frameIndex: int = - 1) → QSizeF¶
- Parameters
frameIndex (int = -1) –
- Return type
QSizeF
- getTableContents(self, contents: object) → bool¶
Fetches the contents used for the cells in the table.
- Return type
bool
- Returns
True
if table contents were successfully retrieved.- Parameters
contents (object) –
QgsLayoutTableContents
to store retrieved row data in
- gridColor(self) → QColor¶
Returns the color used for grid lines in the table.
See also
See also
See also
- Return type
QColor
- gridStrokeWidth(self) → float¶
Returns the width of grid lines in the table in mm.
See also
See also
See also
- Return type
float
- headerFont(self) → QFont¶
Returns the font used to draw header text in the table.
See also
See also
Deprecated since version use:
headerTextFormat()
instead- Return type
QFont
- headerFontColor(self) → QColor¶
Returns the color used to draw header text in the table.
See also
See also
See also
Deprecated since version use:
headerTextFormat()
instead- Return type
QColor
- headerHAlignment(self) → QgsLayoutTable.HeaderHAlignment¶
Returns the horizontal alignment for table headers.
See also
- Return type
- headerMode(self) → QgsLayoutTable.HeaderMode¶
Returns the display mode for headers in the table. This property controls if and where headers are shown in the table.
See also
- Return type
- headerTextFormat(self) → QgsTextFormat¶
Returns the format used to draw header text in the table.
See also
See also
New in version 3.16.
- Return type
- horizontalAlignmentForCell(self, row: int, column: int) → Qt.Alignment¶
Returns the horizontal alignment to use for the cell at the specified
row
andcolumn
.See also
New in version 3.16.
- Parameters
row (int) –
column (int) –
- Return type
Qt.Alignment
- horizontalGrid(self) → bool¶
Returns whether the grid’s horizontal lines are drawn in the table.
See also
See also
See also
See also
- Return type
bool
- isSignalConnected(self, QMetaMethod) → bool¶
- minFrameSize(self, frameIndex: int = - 1) → QSizeF¶
- Parameters
frameIndex (int = -1) –
- Return type
QSizeF
- readObjectPropertiesFromElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool¶
Sets object properties from a DOM element
- Parameters
parentElement – is the parent DOM element for the object
document – DOM document
context – read write context
- Returns
True
if read was successful
See also
- readPropertiesFromElement(self, itemElem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext) → bool¶
- Parameters
itemElem (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool
- recalculateFrameSizes(self)¶
- recalculateTableSize(self)¶
Recalculates and updates the size of the table and all table frames.
- receivers(self, PYQT_SIGNAL) → int¶
- refresh(self)¶
- refreshAttributes(self)¶
Refreshes the contents shown in the table by querying for new data. This also causes the column widths and size of the table to change to accommodate the new data.
- render(self, context: QgsLayoutItemRenderContext, renderExtent: QRectF, frameIndex: int)¶
- Parameters
context (QgsLayoutItemRenderContext) –
renderExtent (QRectF) –
frameIndex (int) –
- rowRange(self, context: QgsRenderContext, frameIndex: int) → Tuple[int, int]¶
Calculates a range of rows which should be visible in a given frame.
- Parameters
context (QgsRenderContext) – render context
frameIndex (int) – index number for frame
- Return type
Tuple[int, int]
- Returns
row range
- rowsVisible(self, context: QgsRenderContext, frameHeight: float, firstRow: int, includeHeader: bool, includeEmptyRows: bool) → int¶
Calculates how many content rows would be visible within a frame of the specified height.
- Parameters
context (QgsRenderContext) – render context
frameHeight (float) – height of frame
firstRow (int) – index of first row visible in frame (where 0 = first row in table)
includeHeader (bool) – set to
True
if frame would include a header rowincludeEmptyRows (bool) – set to
True
to also include rows which would be empty in the returned count. For instance, if the frame would include all table content rows and have space left for extra rows then setting this parameter toTrue
would also include a count of these extra blank rows.
- Returns
number of visible content rows (excluding header row)
rowsVisible(self, context:
QgsRenderContext
, frameIndex: int, firstRow: int, includeEmptyRows: bool) -> int Calculates how many content rows are visible within a given frame.- Parameters
context – render context
frameIndex – index number for frame
firstRow – index of first row visible in frame (where 0 = first row in table)
includeEmptyRows – set to
True
to also include rows which would be empty in the returned count. For instance, if the frame would include all table content rows and have space left for extra rows then setting this parameter toTrue
would also include a count of these extra blank rows.
- Return type
int
- Returns
number of visible content rows (excludes header rows)
- scopeForCell(self, row: int, column: int) → QgsExpressionContextScope¶
Creates a new
QgsExpressionContextScope
for the cell atrow
,column
.New in version 3.16.
- Parameters
row (int) –
column (int) –
- Return type
- sender(self) → QObject¶
- senderSignalIndex(self) → int¶
- setBackgroundColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])¶
Sets the
color
used for background of table.See also
See also
- Parameters
color (Union[QColor) –
- setCellMargin(self, margin: float)¶
Sets the
margin
distance in mm between cell borders and their contents.See also
- Parameters
margin (float) –
- setCellStyle(self, group: QgsLayoutTable.CellStyleGroup, style: QgsLayoutTableStyle)¶
Sets the cell
style
for a cellgroup
.See also
- Parameters
group (QgsLayoutTable.CellStyleGroup) –
style (QgsLayoutTableStyle) –
- setColumns(self, columns: Iterable[QgsLayoutTableColumn])¶
Replaces the columns in the table with a specified list of
QgsLayoutTableColumns
.- Parameters
columns (Iterable[QgsLayoutTableColumn]) – list of
QgsLayoutTableColumns
to show in table.
See also
- setContentFont(self, font: QFont)¶
Sets the
font
used to draw text in table body cells.See also
See also
Deprecated since version use:
setContentTextFormat()
instead- Parameters
font (QFont) –
- setContentFontColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])¶
Sets the
color
used to draw text in table body cells.See also
See also
See also
Deprecated since version use:
setContentTextFormat()
instead- Parameters
color (Union[QColor) –
- setContentTextFormat(self, format: QgsTextFormat)¶
Sets the
format
used to draw content text in the table.See also
See also
New in version 3.16.
- Parameters
format (QgsTextFormat) –
- setEmptyTableBehavior(self, mode: QgsLayoutTable.EmptyTableMode)¶
Sets the behavior
mode
for empty tables with no content rows.See also
- Parameters
mode (QgsLayoutTable.EmptyTableMode) –
- setEmptyTableMessage(self, message: str)¶
Sets the
message
for empty tables with no content rows. This message is displayed in the table body if the empty table behavior is set to ShowMessage.See also
See also
- Parameters
message (str) –
- setGridColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])¶
Sets the
color
used for grid lines in the table.See also
See also
See also
- Parameters
color (Union[QColor) –
- setGridStrokeWidth(self, width: float)¶
Sets the
width
in mm for grid lines in the table.See also
See also
See also
- Parameters
width (float) –
- setHeaderFont(self, font: QFont)¶
Sets the
font
used to draw header text in the table.See also
See also
Deprecated since version use:
setHeaderTextFormat()
instead- Parameters
font (QFont) –
- setHeaderFontColor(self, color: Union[QColor, Qt.GlobalColor, QGradient])¶
Sets the
color
used to draw header text in the table.See also
See also
See also
Deprecated since version use:
setHeaderTextFormat()
instead- Parameters
color (Union[QColor) –
- setHeaderHAlignment(self, alignment: QgsLayoutTable.HeaderHAlignment)¶
Sets the horizontal
alignment
for table headers.See also
- Parameters
alignment (QgsLayoutTable.HeaderHAlignment) –
- setHeaderMode(self, mode: QgsLayoutTable.HeaderMode)¶
Sets the display
mode
for headers in the table. This property controls if and where headers are shown in the table.See also
- Parameters
mode (QgsLayoutTable.HeaderMode) –
- setHeaderTextFormat(self, format: QgsTextFormat)¶
Sets the
format
used to draw header text in the table.See also
See also
New in version 3.16.
- Parameters
format (QgsTextFormat) –
- setHorizontalGrid(self, horizontalGrid: bool)¶
Sets whether the grid’s horizontal lines should be drawn in the table
- Parameters
horizontalGrid (bool) – set to
True
to draw grid’s horizontal lines
See also
See also
See also
See also
- setShowEmptyRows(self, showEmpty: bool)¶
Sets whether empty rows should be drawn. Tables default to hiding empty rows.
- Parameters
showEmpty (bool) – set to
True
to show empty rows in the table
See also
- setShowGrid(self, showGrid: bool)¶
Sets whether grid lines should be drawn in the table
- Parameters
showGrid (bool) – set to
True
to show grid lines
See also
See also
See also
- setSortColumns(self, sortColumns: Iterable[QgsLayoutTableColumn])¶
Replaces the sorting columns in the table with a specified list of
QgsLayoutTableSortColumns
.- Parameters
sortColumns (Iterable[QgsLayoutTableColumn]) – list of
QgsLayoutTableColumns
used to sort the table.
See also
New in version 3.14.
- setVerticalGrid(self, verticalGrid: bool)¶
Sets whether the grid’s vertical lines should be drawn in the table
- Parameters
verticalGrid (bool) – set to
True
to draw grid’s vertical lines
See also
See also
See also
See also
- setWrapBehavior(self, behavior: QgsLayoutTable.WrapBehavior)¶
Sets the wrap
behavior
for the table, which controls how text within cells is automatically wrapped.See also
- Parameters
behavior (QgsLayoutTable.WrapBehavior) –
- showEmptyRows(self) → bool¶
Returns whether empty rows are drawn in the table.
See also
- Return type
bool
- showGrid(self) → bool¶
Returns whether grid lines are drawn in the table
See also
See also
See also
- Return type
bool
- sortColumns(self) → List[QgsLayoutTableColumn]¶
Returns a reference to the list of
QgsLayoutTableSortColumns
shown in the tableSee also
New in version 3.14.
- Return type
List[QgsLayoutTableColumn]
- textFormatForCell(self, row: int, column: int) → QgsTextFormat¶
Returns the text format to use for the cell at the specified
row
andcolumn
.See also
New in version 3.16.
- Parameters
row (int) –
column (int) –
- Return type
- textFormatForHeader(self, column: int) → QgsTextFormat¶
Returns the text format to use for the header cell at the specified
column
.See also
New in version 3.16.
- Parameters
column (int) –
- Return type
- timerEvent(self, QTimerEvent)¶
- totalHeight(self) → float¶
- Return type
float
- totalSize(self) → QSizeF¶
- Return type
QSizeF
- totalWidth(self) → float¶
- Return type
float
- verticalAlignmentForCell(self, row: int, column: int) → Qt.Alignment¶
Returns the vertical alignment to use for the cell at the specified
row
andcolumn
.See also
New in version 3.16.
- Parameters
row (int) –
column (int) –
- Return type
Qt.Alignment
- verticalGrid(self) → bool¶
Returns whether the grid’s vertical lines are drawn in the table.
See also
See also
See also
See also
- Return type
bool
- wrapBehavior(self) → QgsLayoutTable.WrapBehavior¶
Returns the wrap behavior for the table, which controls how text within cells is automatically wrapped.
See also
- Return type
- writeObjectPropertiesToElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool¶
Stores object properties within an XML DOM element.
- Parameters
parentElement – is the parent DOM element to store the object’s properties in
document – DOM document
context – read write context
- Returns
True
if write was successful
See also
- writePropertiesToElement(self, elem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext) → bool¶
- Parameters
elem (QDomElement) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool