TermTk.TTkWidgets.TTkModelView.tablewidget

TTkHeaderView

class TTkHeaderView(visible=True)[source]

This is a placeholder for a proper “TTkHeaderView”

hide() None[source]
setVisible(visible: bool) None[source]
show() None[source]

TTkTableWidget

class TTkTableWidget(*, tableModel: TTkAbstractTableModel = None, vSeparator: bool = True, hSeparator: bool = True, vHeader: bool = True, hHeader: bool = True, sortingEnabled=False, dataPadding=1, **kwargs)[source]

A TTkTableWidget implements a table view that displays items from a model.

    Customer Id     ╿First Name ╿Last Name   ╿Company                         ╿City                ╿
1  │DD37Cf93aecA6Dc │Sheryl     │Baxter      │Rasmussen Group                 │East Leonard        │
╾╌╌┼────────────────┼───────────┼────────────┼────────────────────────────────┼────────────────────┤
2  │1Ef7b82A4CAAD10 │Preston    │Lozano      │Vega-Gentry                     │East Jimmychester   │
╾╌╌┼────────────────┼───────────┼────────────┼────────────────────────────────┼────────────────────┤
3  │6F94879bDAfE5a6 │Roy        │Berry       │Murillo-Perry                   │Isabelborough       │
╾╌╌┼────────────────┼───────────┼────────────┼────────────────────────────────┼────────────────────┤
4  │5Cef8BFA16c5e3c │Linda      │Olsen       │Dominguez, Mcmillan and Donovan │Bensonview          │
╾╌╌┼────────────────┼───────────┼────────────┼────────────────────────────────┼────────────────────┤
5  │053d585Ab6b3159 │Joanna     │Bender      │Martin, Lang and Andrade        │West Priscilla      │
╾╌╌┼────────────────┼───────────┼────────────┼────────────────────────────────┼────────────────────┤
6  │2d08FB17EE273F4 │Aimee      │Downs       │Steele Group                    │Chavezborough       │
╾╌╌┴────────────────┴───────────┴────────────┴────────────────────────────────┴────────────────────┘

The TTkTableWidget class is one of the Model/View Classes and is part of TermTk’s model/view framework.

TTkTableWidget implements the methods to allow it to display data provided by models derived from the TTkAbstractTableModel class.

Navigation

You can navigate the cells in the table by clicking on a cell with the mouse, or by using the arrow keys, you can also hit Tab and Backtab to move from cell to cell.

Visual Appearance

The table has a vertical header that can be obtained using the verticalHeader() function, and a horizontal header that is available through the horizontalHeader() function. The height of each row in the table can be set using setRowHeight(); similarly, the width of columns can be set using setColumnWidth().

They can be selected with selectRow() and selectColumn(). The table will show a grid depending on the setHSeparatorVisibility() setVSeparatorVisibility() methods.

The items shown in a table view, like those in the other item views, are rendered and edited using standard delegates. However, for some tasks it is sometimes useful to be able to insert widgets in a table instead. Widgets are set for particular indexes with the setIndexWidget() function, and later retrieved with indexWidget().

By default, the cells in a table do not expand to fill the available space. You can make the cells fill the available space by stretching the last header section.

To distribute the available space according to the space requirement of each column or row, call the view’s resizeColumnsToContents() or resizeRowsToContents() functions.

Parameters
  • tableModel (TTkAbstractTableModel) – the model for the view to present.

  • vSeparator (bool, optional) – show the vertical separators, defaults to True

  • hSeparator (bool, optional) – show the horizontal separators, defaults to True

  • vHeader (bool, optional) – show the vertical header, defaults to True

  • hHeader (bool, optional) – show the horizontal header, defaults to True

  • sortingEnabled (bool, optional) – enable the column sorting, defaults to False

  • dataPadding (int, optional) – the right column padding, defaults to 1

Signals

signal cellChanged(row, col)

This signal is emitted whenever the data of the item in the cell specified by row and column has changed.

Parameters
  • row (int) – the row

  • col (int) – the column

signal cellClicked(row, col)

This signal is emitted whenever a cell in the table is clicked. The row and column specified is the cell that was clicked.

Parameters
  • row (int) – the row

  • col (int) – the column

signal cellDoubleClicked(row, col)

This signal is emitted whenever a cell in the table is double clicked. The row and column specified is the cell that was double clicked.

Parameters
  • row (int) – the row

  • col (int) – the column

signal cellEntered(row, col)

This signal is emitted when the mouse cursor enters a cell. The cell is specified by row and column.

Parameters
  • row (int) – the row

  • col (int) – the column

signal currentCellChanged(currRow, currCol, prevRow, prevCol)

This signal is emitted whenever the current cell changes. The cell specified by prevRow and prevCol is the cell that previously had the focus, the cell specified by currRow and currCol is the new current cell.

Parameters
  • currRow (int) – the current row

  • currColumn (int) – the current column

  • prevRow (int) – the previous row

  • prevCol (int) – the previous column

addWidget(widget)

Warning

Method Deprecated,

use TTkWidget -> layout -> addWidget

i.e.

parentWidget.layout().addWidget(childWidget)
classStyle = {'default': {'color': <TermTk.TTkCore.color._TTkColor object>, 'currentColor': <TermTk.TTkCore.color.TTkColor object>, 'headerColor': <TermTk.TTkCore.color.TTkColor object>, 'hoverColor': <TermTk.TTkCore.color.TTkColor object>, 'lineColor': <TermTk.TTkCore.color.TTkColor object>, 'selectedColor': <TermTk.TTkCore.color.TTkColor object>, 'separatorColor': <TermTk.TTkCore.color.TTkColor object>}, 'disabled': {'color': <TermTk.TTkCore.color.TTkColor object>, 'currentColor': <TermTk.TTkCore.color.TTkColor object>, 'headerColor': <TermTk.TTkCore.color.TTkColor object>, 'hoverColor': <TermTk.TTkCore.color.TTkColor object>, 'lineColor': <TermTk.TTkCore.color.TTkColor object>, 'selectedColor': <TermTk.TTkCore.color.TTkColor object>, 'separatorColor': <TermTk.TTkCore.color.TTkColor object>}}

default style

clearSelection() None[source]

Deselects all selected items. The current index will not be changed.

close()
columnCount() int[source]

Returns the number of columns.

Returns

int

copy() None[source]

Copies any selected cells to the clipboard.

currentColumn() int[source]

Returns the column of the current item.

Returns

int

currentRow() int[source]

Returns the row of the current item.

Returns

int

cut() None[source]

Copies the selected ccells to the clipboard and deletes them from the table.

dragEnterEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkDropEvent) – The drop event

Returns

True if the event has been handled

Return type

bool

dragLeaveEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkDropEvent) – The drop event

Returns

True if the event has been handled

Return type

bool

dragMoveEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkDropEvent) – The drop event

Returns

True if the event has been handled

Return type

bool

dropEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive drag events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkDropEvent) – The drop event

Returns

True if the event has been handled

Return type

bool

enterEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive mouse enter events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

getPadding() -> (<class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>)

Retrieve the widget padding sizes

Returns

list[top, bottom, left, right]: the 4 padding sizes

hSeparatorVisibility() bool[source]

Returns the visibility status of the horizontal separator

Returns

bool

hide()
horizontalHeader() TTkHeaderView[source]

Returns the table view’s horizontal header.

Returns

TTkHeaderView

isRedoAvailable() bool[source]
Returns

bool

isSortingEnabled() bool[source]

This property holds whether sorting is enabled If this property is true, sorting is enabled for the table. If this property is false, sorting is not enabled. The default value is false.

Note: . Setting the property to true with setSortingEnabled() immediately triggers a call to sortByColumn() with the current sort section and order.

Returns

bool

isUndoAvailable() bool[source]
Returns

bool

keyEvent(evt)[source]

This event handler, can be reimplemented in a subclass to receive key events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkKeyEvent) – The keyboard event

Returns

True if the event has been handled

Return type

bool

keyPressEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive key press events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkKeyEvent) – The keyboard event

Returns

True if the event has been handled

Return type

bool

keyReleaseEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive key release events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkKeyEvent) – The keyboard event

Returns

True if the event has been handled

Return type

bool

layout()

Get the layout

Returns

The layout used

Return type

TTkLayout or derived

leaveEvent(evt)[source]

This event handler, can be reimplemented in a subclass to receive mouse leave events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

lowerWidget()
model() TTkAbstractTableModel[source]

Returns the model that this view is presenting.

Returns

TTkAbstractTableModel

mouseDoubleClickEvent(evt)[source]

This event handler, can be reimplemented in a subclass to receive mouse click events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

mouseDragEvent(evt) bool[source]

This event handler, can be reimplemented in a subclass to receive mouse drag events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

mouseEvent(evt)

Caution

Don’t touch this!

mouseMoveEvent(evt) bool[source]

This event handler, can be reimplemented in a subclass to receive mouse move events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

mousePressEvent(evt) bool[source]

This event handler, can be reimplemented in a subclass to receive mouse press events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

mouseReleaseEvent(evt) bool[source]

This event handler, can be reimplemented in a subclass to receive mouse release events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

mouseTapEvent(evt) bool

This event handler, can be reimplemented in a subclass to receive mouse click events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool

move(x: int, y: int)

Move the widget

Parameters
  • x (int) – x position

  • y (int) – y position

moveEvent(x: int, y: int)

Event Callback triggered after a successful move

name() str
paintChildCanvas()

Caution

Don’t touch this!

paintEvent(canvas) None[source]

Paint Event callback, this need to be overridden in the widget.

paste() None[source]

Pastes the text/cells from the clipboard into the table at the current cursor position.

raiseWidget(raiseParent=True)
redo() None[source]

Redoes the last operation if redo is available.

removeWidget(widget)

Warning

Method Deprecated,

use TTkWidget -> layout -> removeWidget

i.e.

parentWidget.layout().removeWidget(childWidget)
resize(w: int, h: int)

Resize the widget

Parameters
  • w (int) – the new width

  • h (int) – the new height

resizeColumnToContents(column: int) None[source]

Resizes the given column based on the size hints of the delegate used to render each item in the column.

Parameters

column (int) – the column to be resized

resizeColumnsToContents() None[source]

Resizes all columns based on the size hints of the delegate used to render each item in the columns.

resizeEvent(w, h)

Event Callback triggered after a successful resize

resizeRowToContents(row: int) None[source]

Resizes the given row based on the size hints of the delegate used to render each item in the row.

Parameters

row (int) – the row to be resized

resizeRowsToContents() None[source]

Resizes all rows based on the size hints of the delegate used to render each item in the rows.

rowCount() int[source]

Returns the number of rows.

Returns

int

selectAll() None[source]

Selects all items in the view. This function will use the selection behavior set on the view when selecting.

selectColumn(col: int) None[source]

Selects the given column in the table view

Parameters

col (int) – the column to be selected

selectRow(row: int) None[source]

Selects the given row in the table view

Parameters

row (int) – the row to be selected

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

Sets the width of the given column.

Parameters
  • column (int) – the column

  • width (int) – its width

setDisabled(disabled=True)
setEnabled(enabled: bool = True)
setFocus()
setGeometry(x: int, y: int, w: int, h: int)

Resize and move the widget

Parameters
  • x (int) – x position

  • y (int) – y position

  • w (int) – the new width

  • h (int) – the new height

setHSeparatorVisibility(visibility: bool) None[source]

Set the the visibility of the horizontal separators (lines)

     Customer Id      First Name  Last Name   Company
1  │ DD37Cf93aecA6Dc  Sheryl      Baxter      Rasmussen Group
╾╌╌┼───────────────────────────────────────────────────────────
2  │ 1Ef7b82A4CAAD10  Preston     Lozano      Vega-Gentry
╾╌╌┼───────────────────────────────────────────────────────────
3  │ 6F94879bDAfE5a6  Roy         Berry       Murillo-Perry
╾╌╌┼───────────────────────────────────────────────────────────
Parameters

visibility (bool) – the visibility status

setModel(model: TTkAbstractTableModel) None[source]

Sets the model for the view to present.

Parameters

model (TTkAbstractTableModel) –

setName(name: str)
setPadding(top: int, bottom: int, left: int, right: int)

Set the padding of the widget

Parameters
  • top (int) – top padding

  • bottom (int) – bottom padding

  • left (int) – left padding

  • right (int) – right padding

setRowHeight(row: int, height: int) None[source]

Sets the height of the given row.

Parameters
  • row (int) – the row

  • height (int) – its height

setSelection(pos: tuple[int, int], size: tuple[int, int], flags: TTkItemSelectionModel) None[source]

Selects the items within the given rect and in accordance with the specified selection flags.

Parameters
  • pos (tuple[int,int]) – the x,y position of the rect

  • size (tuple[int,int]) – the width,height of the rect used for the selection

  • flags (TTkItemSelectionModel) – the selection model used (i.e. Select)

setSortingEnabled(enable: bool) None[source]

If enable is true, enables sorting for the table and immediately trigger a call to sortByColumn() with the current sort section and order

Note: Setter function for property sortingEnabled.

Parameters

enable (bool) – the availability of undo

setVSeparatorVisibility(visibility: bool)[source]

Set the the visibility of the vertical separators (lines)

     Customer Id     ╿First Name ╿Last Name   ╿Company                     ╿
1  │ DD37Cf93aecA6Dc │Sheryl     │Baxter      │Rasmussen Group             │
2  │ 1Ef7b82A4CAAD10 │Preston    │Lozano      │Vega-Gentry                 │
3  │ 6F94879bDAfE5a6 │Roy        │Berry       │Murillo-Perry               │
4  │ 5Cef8BFA16c5e3c │Linda      │Olsen       │Dominguez, Mcmillan and Don │
5  │ 053d585Ab6b3159 │Joanna     │Bender      │Martin, Lang and Andrade    │
6  │ 2d08FB17EE273F4 │Aimee      │Downs       │Steele Group                │
Parameters

visibility (bool) – the visibility status

setVisible(visible: bool)
show()
sortByColumn(column: int, order: SortOrder) None[source]

Sorts the model by the values in the given column and order.

column may be -1, in which case no sort indicator will be shown and the model will return to its natural, unsorted order. Note that not all models support this and may even crash in this case.

Parameters
  • column (bool) – the column used for the sorting, -1 to keep the table unsorted

  • order (SortOrder) – the sort order

undo() None[source]

Undoes the last operation if undo is available.

unselectColumn(column: int) None[source]

Unselects the given column in the table view

Parameters

column (int) – the column to be unselected

unselectRow(row: int) None[source]

Unselects the given row in the table view

Parameters

row (int) – the row to be unselected

vSeparatorVisibility() bool[source]

Returns the visibility status of the vertical separator

Returns

bool

verticalHeader() TTkHeaderView[source]

Returns the table view’s vertical header.

Returns

TTkHeaderView

wheelEvent(evt)

This event handler, can be reimplemented in a subclass to receive mouse wheel events for the widget.

Note

Reimplement this function to handle this event

Parameters

evt (TTkMouseEvent) – The mouse event

Returns

True if the event has been handled

Return type

bool