Class: QgsTableEditorWidget

A reusable widget for editing simple spreadsheet-style tables.

Table content is retrieved and set using the QgsTableContents class. The editor has support for table foreground and background colors, and numeric formats.

Added in version 3.12.

QgsTableEditorWidget

QgsTableEditorWidget

Class Hierarchy

Inheritance diagram of qgis.gui.QgsTableEditorWidget

Base classes

QTableWidget

QTableView

QAbstractItemView

QAbstractScrollArea

QFrame

QWidget

QObject

QPaintDevice

Methods

canMergeSelection

Returns True if a selection has been made which can be merged.

canSplitSelection

Returns True if a selection has been made which can be split.

clearSelectedCells

Clears the contents of the currently selected cells.

columnsAssociatedWithSelection

Returns a list of the columns associated with the current table selected cells.

deleteColumns

Deletes all columns associated with the current selected cells.

deleteRows

Deletes all rows associated with the current selected cells.

expandColumnSelection

Expands out the selection to include whole columns associated with the current selected cells.

expandRowSelection

Expands out the selection to include whole rows associated with the current selected cells.

hasMixedSelectionNumericFormat

Returns True if the current selection has a mix of numeric formats.

insertColumnsAfter

Inserts new columns after the current selection.

insertColumnsBefore

Inserts new columns before the current selection.

insertRowsAbove

Inserts new rows above the current selection.

insertRowsBelow

Inserts new rows below the current selection.

isHeaderCellSelected

Returns True if any header cells are selected.

mergeSelectedCells

Merges selected table cells.

rowsAssociatedWithSelection

Returns a list of the rows associated with the current table selected cells.

selectionBackgroundColor

Returns the background color for the currently selected cells.

selectionCellProperty

Returns the QgsProperty used for the contents of the currently selected cells.

selectionColumnWidth

Returns the width (in millimeters) of the columns associated with the current selection, or 0 if an automatic column width is desired.

selectionForegroundColor

Returns the foreground color for the currently selected cells.

selectionHorizontalAlignment

Returns the horizontal alignment for the currently selected cells.

selectionNumericFormat

Returns the numeric format used for the currently selected cells, or None if the selection has no numeric format set.

selectionRowHeight

Returns the height (in millimeters) of the rows associated with the current selection, or 0 if an automatic row height is desired, or -1 if the selection has mixed row heights.

selectionTextFormat

Returns the text format for the currently selected cells.

selectionVerticalAlignment

Returns the horizontal alignment for the currently selected cells.

setIncludeTableHeader

Sets whether the table includes a header row.

setSelectionBackgroundColor

Sets the background color for the currently selected cells.

setSelectionCellProperty

Sets the cell contents QgsProperty for the currently selected cells.

setSelectionColumnWidth

Sets the column width (in millimeters) for the currently selected columns, or 0 for automatic column width.

setSelectionForegroundColor

Sets the foreground color for the currently selected cells.

setSelectionHorizontalAlignment

Sets the horizontal alignment for the currently selected cells.

setSelectionNumericFormat

Sets the numeric format to use for the currently selected cells.

setSelectionRowHeight

Sets the row height (in millimeters) for the currently selected rows, or 0 for automatic row height.

setSelectionTextFormat

Sets the text format for the selected cells.

setSelectionVerticalAlignment

Sets the vertical alignment for the currently selected cells.

setTableColumnWidth

Sets the configured column width for the specified column.

setTableContents

Sets the contents to show in the editor widget.

setTableHeaders

Sets the table headers.

setTableRowHeight

Sets the configured row height for the specified row.

splitSelectedCells

Splits (un-merges) selected table cells.

tableColumnWidth

Returns the configured column width for the specified column, or 0 if an automatic width should be used for the column.

tableContents

Returns the current contents of the editor widget table.

tableHeaders

Returns the table header values.

tableRowHeight

Returns the configured row height for the specified row, or 0 if an automatic height should be used for the row.

Signals

activeCellChanged

Emitted whenever the active (or selected) cell changes in the widget.

tableChanged

Emitted whenever the table contents are changed.

class qgis.gui.QgsTableEditorWidget[source]

Bases: QTableWidget

__init__(parent: QWidget | None = None)

Constructor for QgsTableEditorWidget with the specified parent widget.

Parameters:

parent (Optional[QWidget] = None)

signal activeCellChanged[source]

Emitted whenever the active (or selected) cell changes in the widget.

canMergeSelection(self) bool[source]

Returns True if a selection has been made which can be merged.

Added in version 3.40.

Return type:

bool

canSplitSelection(self) bool[source]

Returns True if a selection has been made which can be split.

Added in version 3.40.

Return type:

bool

clearSelectedCells(self)[source]

Clears the contents of the currently selected cells.

columnsAssociatedWithSelection(self) List[int]

Returns a list of the columns associated with the current table selected cells.

Return type:

List[int]

deleteColumns(self)[source]

Deletes all columns associated with the current selected cells.

See also

deleteRows()

deleteRows(self)[source]

Deletes all rows associated with the current selected cells.

See also

deleteColumns()

expandColumnSelection(self)[source]

Expands out the selection to include whole columns associated with the current selected cells.

expandRowSelection(self)[source]

Expands out the selection to include whole rows associated with the current selected cells.

hasMixedSelectionNumericFormat(self) bool[source]

Returns True if the current selection has a mix of numeric formats.

Return type:

bool

insertColumnsAfter(self)[source]

Inserts new columns after the current selection.

insertColumnsBefore(self)[source]

Inserts new columns before the current selection.

insertRowsAbove(self)[source]

Inserts new rows above the current selection.

insertRowsBelow(self)[source]

Inserts new rows below the current selection.

isHeaderCellSelected(self) bool[source]

Returns True if any header cells are selected.

Return type:

bool

mergeSelectedCells(self)[source]

Merges selected table cells.

Added in version 3.40.

rowsAssociatedWithSelection(self) List[int]

Returns a list of the rows associated with the current table selected cells.

Return type:

List[int]

selectionBackgroundColor(self) QColor[source]

Returns the background color for the currently selected cells.

If the selected cells have a mix of different background colors then an invalid color will be returned.

Return type:

QColor

selectionCellProperty(self) QgsProperty[source]

Returns the QgsProperty used for the contents of the currently selected cells.

If the returned value is a default constructed QgsProperty, then the selected cells have a mix of different properties.

Added in version 3.16.

Return type:

QgsProperty

selectionColumnWidth(self) float[source]

Returns the width (in millimeters) of the columns associated with the current selection, or 0 if an automatic column width is desired.

Return type:

float

selectionForegroundColor(self) QColor[source]

Returns the foreground color for the currently selected cells.

If the selected cells have a mix of different foreground colors then an invalid color will be returned.

Deprecated since version 3.40: Use selectionTextFormat() instead.

Return type:

QColor

selectionHorizontalAlignment(self) Qt.Alignment[source]

Returns the horizontal alignment for the currently selected cells.

If the returned value contains both horizontal and vertical alignment flags, then the selected cells have a mix of different horizontal alignments.

Return type:

Qt.Alignment

selectionNumericFormat(self) QgsNumericFormat | None[source]

Returns the numeric format used for the currently selected cells, or None if the selection has no numeric format set.

If the selected cells have a mix of different formats then None will be returned.

Return type:

Optional[QgsNumericFormat]

selectionRowHeight(self) float[source]

Returns the height (in millimeters) of the rows associated with the current selection, or 0 if an automatic row height is desired, or -1 if the selection has mixed row heights.

Return type:

float

selectionTextFormat(self) QgsTextFormat[source]

Returns the text format for the currently selected cells.

Returns an invalid QgsTextFormat if the selection has mixed text format.

Added in version 3.16.

Return type:

QgsTextFormat

selectionVerticalAlignment(self) Qt.Alignment[source]

Returns the horizontal alignment for the currently selected cells.

If the returned value contains both horizontal and vertical alignment flags, then the selected cells have a mix of different vertical alignments.

Return type:

Qt.Alignment

setIncludeTableHeader(self, included: bool)[source]

Sets whether the table includes a header row.

Parameters:

included (bool)

setSelectionBackgroundColor(self, color: QColor | Qt.GlobalColor)[source]

Sets the background color for the currently selected cells.

Parameters:

color (Union[QColor, Qt.GlobalColor])

setSelectionCellProperty(self, property: QgsProperty)[source]

Sets the cell contents QgsProperty for the currently selected cells.

Added in version 3.16.

Parameters:

property (QgsProperty)

setSelectionColumnWidth(self, height: float)[source]

Sets the column width (in millimeters) for the currently selected columns, or 0 for automatic column width.

Parameters:

height (float)

setSelectionForegroundColor(self, color: QColor | Qt.GlobalColor)[source]

Sets the foreground color for the currently selected cells.

Deprecated since version 3.40: Use setSelectionTextFormat() instead.

Parameters:

color (Union[QColor, Qt.GlobalColor])

setSelectionHorizontalAlignment(self, alignment: Qt.Alignment | Qt.AlignmentFlag)[source]

Sets the horizontal alignment for the currently selected cells.

Added in version 3.16.

Parameters:

alignment (Union[Qt.Alignment, Qt.AlignmentFlag])

setSelectionNumericFormat(self, format: QgsNumericFormat | None)[source]

Sets the numeric format to use for the currently selected cells.

Ownership of format is transferred to the widget.

Parameters:

format (Optional[QgsNumericFormat])

setSelectionRowHeight(self, height: float)[source]

Sets the row height (in millimeters) for the currently selected rows, or 0 for automatic row height.

Parameters:

height (float)

setSelectionTextFormat(self, format: QgsTextFormat)[source]

Sets the text format for the selected cells.

Added in version 3.16.

Parameters:

format (QgsTextFormat)

setSelectionVerticalAlignment(self, alignment: Qt.Alignment | Qt.AlignmentFlag)[source]

Sets the vertical alignment for the currently selected cells.

Added in version 3.16.

Parameters:

alignment (Union[Qt.Alignment, Qt.AlignmentFlag])

setTableColumnWidth(self, column: int, width: float)[source]

Sets the configured column width for the specified column. Set width to 0 if an automatic width should be used for the column.

This should be called after a call to setTableContents().

Parameters:
  • column (int)

  • width (float)

setTableContents(self, contents: Any)[source]

Sets the contents to show in the editor widget.

See also

tableContents()

Parameters:

contents (Any)

setTableHeaders(self, headers: Iterable[Any])[source]

Sets the table headers.

See also

tableHeaders()

Parameters:

headers (Iterable[Any])

setTableRowHeight(self, row: int, height: float)[source]

Sets the configured row height for the specified row. Set height to 0 if an automatic height should be used for the row.

This should be called after a call to setTableContents().

See also

tableRowHeight()

Parameters:
  • row (int)

  • height (float)

splitSelectedCells(self)[source]

Splits (un-merges) selected table cells.

Added in version 3.40.

signal tableChanged[source]

Emitted whenever the table contents are changed.

tableColumnWidth(self, column: int) float[source]

Returns the configured column width for the specified column, or 0 if an automatic width should be used for the column.

Parameters:

column (int)

Return type:

float

tableContents(self) Any[source]

Returns the current contents of the editor widget table.

Return type:

Any

tableHeaders(self) List[Any][source]

Returns the table header values.

Return type:

List[Any]

tableRowHeight(self, row: int) float[source]

Returns the configured row height for the specified row, or 0 if an automatic height should be used for the row.

Parameters:

row (int)

Return type:

float