Class: QgsTableEditorWidget

class qgis.gui.QgsTableEditorWidget(parent: QWidget = None)

Bases: PyQt5.QtWidgets.QTableWidget

Constructor for QgsTableEditorWidget with the specified parent widget.

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.

Methods

actionEvent

changeEvent

childEvent

clearSelectedCells

Clears the contents of the currently selected cells.

closeEditor

closeEvent

columnCountChanged

columnMoved

columnResized

columnsAssociatedWithSelection

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

commitData

connectNotify

contextMenuEvent

create

currentChanged

customEvent

dataChanged

deleteColumns

Deletes all columns associated with the current selected cells.

deleteRows

Deletes all rows associated with the current selected cells.

destroy

dirtyRegionOffset

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

drawFrame

dropEvent

dropIndicatorPosition

dropMimeData

edit

editorDestroyed

enterEvent

event

eventFilter

executeDelayedItemsLayout

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.

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hasMixedSelectionNumericFormat

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

hideEvent

horizontalOffset

horizontalScrollbarAction

horizontalScrollbarValueChanged

indexFromItem

initPainter

initStyleOption

inputMethodEvent

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.

isIndexHidden

isSignalConnected

itemFromIndex

items

keyPressEvent

param event

keyReleaseEvent

leaveEvent

metric

mimeData

mimeTypes

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveCursor

moveEvent

nativeEvent

paintEvent

receivers

resizeEvent

rowCountChanged

rowMoved

rowResized

rowsAboutToBeRemoved

rowsAssociatedWithSelection

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

rowsInserted

scheduleDelayedItemsLayout

scrollContentsBy

scrollDirtyRegion

selectedIndexes

selectionBackgroundColor

Returns the background color for the currently selected cells.

selectionCellProperty

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

selectionChanged

selectionColumnWidth

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

selectionCommand

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.

sender

senderSignalIndex

setDirtyRegion

setIncludeTableHeader

Sets whether the table includes a header row.

setSelection

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.

setState

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.

setViewportMargins

sharedPainter

showEvent

sizeHintForColumn

sizeHintForRow

startDrag

state

supportedDropActions

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.

tabletEvent

timerEvent

updateEditorData

updateEditorGeometries

updateGeometries

updateMicroFocus

verticalOffset

verticalScrollbarAction

verticalScrollbarValueChanged

viewOptions

viewportEvent

viewportMargins

viewportSizeHint

visualRegionForSelection

wheelEvent

Signals

activeCellChanged

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

tableChanged

Emitted whenever the table contents are changed.

actionEvent(self, QActionEvent)
activeCellChanged

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

changeEvent(self, QEvent)
childEvent(self, QChildEvent)
clearSelectedCells(self)

Clears the contents of the currently selected cells.

closeEditor(self, QWidget, QAbstractItemDelegate.EndEditHint)
closeEvent(self, QCloseEvent)
QgsTableEditorWidget.columnCountChanged(self, int, int)
QgsTableEditorWidget.columnMoved(self, int, int, int)
QgsTableEditorWidget.columnResized(self, int, int, int)
columnsAssociatedWithSelection(self)List[int]

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

Return type

List[int]

commitData(self, QWidget)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
QgsTableEditorWidget.currentChanged(self, QModelIndex, QModelIndex)
customEvent(self, QEvent)
QgsTableEditorWidget.dataChanged(self, QModelIndex, QModelIndex, roles: Iterable[int] = [])
deleteColumns(self)

Deletes all columns associated with the current selected cells.

See also

deleteRows()

deleteRows(self)

Deletes all rows associated with the current selected cells.

See also

deleteColumns()

destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
dirtyRegionOffset(self)QPoint
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QDragEnterEvent)
dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
drawFrame(self, QPainter)
dropEvent(self, QDropEvent)
dropIndicatorPosition(self)QAbstractItemView.DropIndicatorPosition
dropMimeData(self, int, int, QMimeData, Qt.DropAction)bool
edit(self, QModelIndex)
edit(self, QModelIndex, QAbstractItemView.EditTrigger, QEvent)bool
editorDestroyed(self, QObject)
enterEvent(self, QEvent)
event(self, QEvent)bool
eventFilter(self, QObject, QEvent)bool
executeDelayedItemsLayout(self)
expandColumnSelection(self)

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

expandRowSelection(self)

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

focusInEvent(self, QFocusEvent)
focusNextChild(self)bool
focusNextPrevChild(self, bool)bool
focusOutEvent(self, QFocusEvent)
focusPreviousChild(self)bool
hasMixedSelectionNumericFormat(self)bool

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

Return type

bool

hideEvent(self, QHideEvent)
horizontalOffset(self)int
horizontalScrollbarAction(self, int)
horizontalScrollbarValueChanged(self, int)
indexFromItem(self, QTableWidgetItem)QModelIndex
initPainter(self, QPainter)
initStyleOption(self, QStyleOptionFrame)
inputMethodEvent(self, QInputMethodEvent)
insertColumnsAfter(self)

Inserts new columns after the current selection.

insertColumnsBefore(self)

Inserts new columns before the current selection.

insertRowsAbove(self)

Inserts new rows above the current selection.

insertRowsBelow(self)

Inserts new rows below the current selection.

isHeaderCellSelected(self)bool

Returns True if any header cells are selected.

Return type

bool

isIndexHidden(self, QModelIndex)bool
isSignalConnected(self, QMetaMethod)bool
itemFromIndex(self, QModelIndex)QTableWidgetItem
items(self, QMimeData)List[QTableWidgetItem]
keyPressEvent(self, event: QKeyEvent)
Parameters

event (QKeyEvent) –

keyReleaseEvent(self, QKeyEvent)
leaveEvent(self, QEvent)
metric(self, QPaintDevice.PaintDeviceMetric)int
mimeData(self, Iterable[QTableWidgetItem])QMimeData
mimeTypes(self)List[str]
mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
moveCursor(self, QAbstractItemView.CursorAction, Union[Qt.KeyboardModifiers, Qt.KeyboardModifier])QModelIndex
moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], sip.voidptr)Tuple[bool, int]
paintEvent(self, QPaintEvent)
receivers(self, PYQT_SIGNAL)int
resizeEvent(self, QResizeEvent)
QgsTableEditorWidget.rowCountChanged(self, int, int)
QgsTableEditorWidget.rowMoved(self, int, int, int)
QgsTableEditorWidget.rowResized(self, int, int, int)
QgsTableEditorWidget.rowsAboutToBeRemoved(self, QModelIndex, int, int)
rowsAssociatedWithSelection(self)List[int]

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

Return type

List[int]

QgsTableEditorWidget.rowsInserted(self, QModelIndex, int, int)
scheduleDelayedItemsLayout(self)
QgsTableEditorWidget.scrollContentsBy(self, int, int)
QgsTableEditorWidget.scrollDirtyRegion(self, int, int)
selectedIndexes(self)List[QModelIndex]
selectionBackgroundColor(self)QColor

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

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.

New in version 3.16.

Return type

QgsProperty

QgsTableEditorWidget.selectionChanged(self, QItemSelection, QItemSelection)
selectionColumnWidth(self)float

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

selectionCommand(self, QModelIndex, event: QEvent = None)QItemSelectionModel.SelectionFlags
selectionForegroundColor(self)QColor

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 use: selectionTextFormat() instead.

Return type

QColor

selectionHorizontalAlignment(self)Qt.Alignment

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

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

QgsNumericFormat

selectionRowHeight(self)float

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

Returns the text format for the currently selected cells.

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

New in version 3.16.

Return type

QgsTextFormat

selectionVerticalAlignment(self)Qt.Alignment

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

sender(self)QObject
senderSignalIndex(self)int
setDirtyRegion(self, QRegion)
setIncludeTableHeader(self, included: bool)

Sets whether the table includes a header row.

See also

includeTableHeader()

Parameters

included (bool) –

setSelection(self, QRect, Union[QItemSelectionModel.SelectionFlags, QItemSelectionModel.SelectionFlag])
setSelectionBackgroundColor(self, color: Union[QColor, Qt.GlobalColor])

Sets the background color for the currently selected cells.

Parameters

color (Union[QColor) –

setSelectionCellProperty(self, property: QgsProperty)

Sets the cell contents QgsProperty for the currently selected cells.

New in version 3.16.

Parameters

property (QgsProperty) –

setSelectionColumnWidth(self, height: float)

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

Parameters

height (float) –

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

Sets the foreground color for the currently selected cells.

Deprecated since version Use: setSelectionTextFormat() instead.

Parameters

color (Union[QColor) –

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

Sets the horizontal alignment for the currently selected cells.

New in version 3.16.

Parameters

alignment (Union[Qt.Alignment) –

setSelectionNumericFormat(self, format: QgsNumericFormat)

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

Ownership of format is transferred to the widget.

Parameters

format (QgsNumericFormat) –

setSelectionRowHeight(self, height: float)

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

Parameters

height (float) –

setSelectionTextFormat(self, format: QgsTextFormat)

Sets the text format for the selected cells.

New in version 3.16.

Parameters

format (QgsTextFormat) –

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

Sets the vertical alignment for the currently selected cells.

New in version 3.16.

Parameters

alignment (Union[Qt.Alignment) –

setState(self, QAbstractItemView.State)
setTableColumnWidth(self, column: int, width: float)

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: object)

Sets the contents to show in the editor widget.

See also

tableContents()

Parameters

contents (object) –

setTableHeaders(self, headers: Iterable[Any])

Sets the table headers.

See also

tableHeaders()

Parameters

headers (Iterable[Any]) –

setTableRowHeight(self, row: int, height: float)

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) –

QgsTableEditorWidget.setViewportMargins(self, int, int, int, int)
setViewportMargins(self, QMargins)None
sharedPainter(self)QPainter
showEvent(self, QShowEvent)
sizeHintForColumn(self, int)int
sizeHintForRow(self, int)int
startDrag(self, Union[Qt.DropActions, Qt.DropAction])
state(self)QAbstractItemView.State
supportedDropActions(self)Qt.DropActions
tableChanged

Emitted whenever the table contents are changed. [signal]

tableColumnWidth(self, column: int)float

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)object

Returns the current contents of the editor widget table.

Return type

object

tableHeaders(self)List[Any]

Returns the table header values.

Return type

List[Any]

tableRowHeight(self, row: int)float

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

tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
updateEditorData(self)
updateEditorGeometries(self)
updateGeometries(self)
updateMicroFocus(self)
verticalOffset(self)int
verticalScrollbarAction(self, int)
verticalScrollbarValueChanged(self, int)
viewOptions(self)QStyleOptionViewItem
viewportEvent(self, QEvent)bool
viewportMargins(self)QMargins
viewportSizeHint(self)QSize
visualRegionForSelection(self, QItemSelection)QRegion
wheelEvent(self, QWheelEvent)