QTableWidget

Inheritance diagram of QTableWidget

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

The PySide.QtGui.QTableWidget class provides an item-based table view with a default model.

Table widgets provide standard table display facilities for applications. The items in a PySide.QtGui.QTableWidget are provided by PySide.QtGui.QTableWidgetItem .

If you want a table that uses your own data model you should use PySide.QtGui.QTableView rather than this class.

Table widgets can be constructed with the required numbers of rows and columns:

tableWidget = QTableWidget(12, 3, self)

Alternatively, tables can be constructed without a given size and resized later:

tableWidget = QTableWidget()
tableWidget.setRowCount(10)
tableWidget.setColumnCount(5)

Items are created ouside the table (with no parent widget) and inserted into the table with PySide.QtGui.QTableWidget.setItem() :

newItem = QTableWidgetItem(tr("%s" % ((row+1)*(column+1))))
tableWidget.setItem(row, column, newItem)

If you want to enable sorting in your table widget, do so after you have populated it with items, otherwise sorting may interfere with the insertion order (see PySide.QtGui.QTableWidget.setItem() for details).

Tables can be given both horizontal and vertical headers. The simplest way to create the headers is to supply a list of strings to the PySide.QtGui.QTableWidget.setHorizontalHeaderLabels() and PySide.QtGui.QTableWidget.setVerticalHeaderLabels() functions. These will provide simple textual headers for the table’s columns and rows. More sophisticated headers can be created from existing table items that are usually constructed outside the table. For example, we can construct a table item with an icon and aligned text, and use it as the header for a particular column:

cubesHeaderItem = QTableWidgetItem(tr("Cubes"))
cubesHeaderItem.setIcon(QIcon(QPixmap(":/Images/cubed.png")))
cubesHeaderItem.setTextAlignment(Qt::AlignVCenter)

The number of rows in the table can be found with PySide.QtGui.QTableWidget.rowCount() , and the number of columns with PySide.QtGui.QTableWidget.columnCount() . The table can be cleared with the PySide.QtGui.QTableWidget.clear() function.

../../_images/windowsxp-tableview.png ../../_images/macintosh-tableview.png ../../_images/plastique-tableview.png
A Windows XP style table widget. A Macintosh style table widget. A Plastique style table widget.

See also

PySide.QtGui.QTableWidgetItem PySide.QtGui.QTableView Model/View Programming

class PySide.QtGui.QTableWidget([parent=None])
class PySide.QtGui.QTableWidget(rows, columns[, parent=None])
Parameters:

Creates a new table view with the given parent .

Creates a new table view with the given rows and columns , and with the given parent .

PySide.QtGui.QTableWidget.cellActivated(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
PySide.QtGui.QTableWidget.cellChanged(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
PySide.QtGui.QTableWidget.cellClicked(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
PySide.QtGui.QTableWidget.cellDoubleClicked(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
PySide.QtGui.QTableWidget.cellEntered(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
PySide.QtGui.QTableWidget.cellPressed(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
PySide.QtGui.QTableWidget.cellWidget(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
Return type:

PySide.QtGui.QWidget

Returns the widget displayed in the cell in the given row and column .

Note

The table takes ownership of the widget.

PySide.QtGui.QTableWidget.clear()

Removes all items in the view. This will also remove all selections. The table dimensions stay the same.

PySide.QtGui.QTableWidget.clearContents()

Removes all items not in the headers from the view. This will also remove all selections. The table dimensions stay the same.

PySide.QtGui.QTableWidget.closePersistentEditor(item)
Parameters:itemPySide.QtGui.QTableWidgetItem

Closes the persistent editor for item .

PySide.QtGui.QTableWidget.column(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
Return type:PySide.QtCore.int

Returns the column for the item .

PySide.QtGui.QTableWidget.columnCount()
Return type:PySide.QtCore.int

This property holds the number of columns in the table.

By default, for a table constructed without row and column counts, this property contains a value of 0.

PySide.QtGui.QTableWidget.currentCellChanged(currentRow, currentColumn, previousRow, previousColumn)
Parameters:
  • currentRowPySide.QtCore.int
  • currentColumnPySide.QtCore.int
  • previousRowPySide.QtCore.int
  • previousColumnPySide.QtCore.int
PySide.QtGui.QTableWidget.currentColumn()
Return type:PySide.QtCore.int

Returns the column of the current item.

PySide.QtGui.QTableWidget.currentItem()
Return type:PySide.QtGui.QTableWidgetItem

Returns the current item.

PySide.QtGui.QTableWidget.currentItemChanged(current, previous)
Parameters:
PySide.QtGui.QTableWidget.currentRow()
Return type:PySide.QtCore.int

Returns the row of the current item.

PySide.QtGui.QTableWidget.dropMimeData(row, column, data, action)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
  • dataPySide.QtCore.QMimeData
  • actionPySide.QtCore.Qt.DropAction
Return type:

PySide.QtCore.bool

PySide.QtGui.QTableWidget.editItem(item)
Parameters:itemPySide.QtGui.QTableWidgetItem

Starts editing the item if it is editable.

PySide.QtGui.QTableWidget.findItems(text, flags)
Parameters:
  • text – unicode
  • flagsPySide.QtCore.Qt.MatchFlags
Return type:

PySide.QtGui.QTableWidget.horizontalHeaderItem(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtGui.QTableWidgetItem

Returns the horizontal header item for column, column , if one has been set; otherwise returns 0.

PySide.QtGui.QTableWidget.indexFromItem(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
Return type:PySide.QtCore.QModelIndex

Returns the PySide.QtCore.QModelIndex assocated with the given item .

PySide.QtGui.QTableWidget.insertColumn(column)
Parameters:columnPySide.QtCore.int

Inserts an empty column into the table at column .

PySide.QtGui.QTableWidget.insertRow(row)
Parameters:rowPySide.QtCore.int

Inserts an empty row into the table at row .

PySide.QtGui.QTableWidget.item(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
Return type:

PySide.QtGui.QTableWidgetItem

Returns the item for the given row and column if one has been set; otherwise returns 0.

PySide.QtGui.QTableWidget.itemActivated(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
PySide.QtGui.QTableWidget.itemAt(x, y)
Parameters:
  • xPySide.QtCore.int
  • yPySide.QtCore.int
Return type:

PySide.QtGui.QTableWidgetItem

Returns the item at the position equivalent to PySide.QtCore.QPoint (ax , ay ) in the table widget’s coordinate system, or returns 0 if the specified point is not covered by an item in the table widget.

PySide.QtGui.QTableWidget.itemAt(p)
Parameters:pPySide.QtCore.QPoint
Return type:PySide.QtGui.QTableWidgetItem

Returns a pointer to the item at the given point , or returns 0 if point is not covered by an item in the table widget.

PySide.QtGui.QTableWidget.itemChanged(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
PySide.QtGui.QTableWidget.itemClicked(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
PySide.QtGui.QTableWidget.itemDoubleClicked(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
PySide.QtGui.QTableWidget.itemEntered(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
PySide.QtGui.QTableWidget.itemFromIndex(index)
Parameters:indexPySide.QtCore.QModelIndex
Return type:PySide.QtGui.QTableWidgetItem

Returns a pointer to the PySide.QtGui.QTableWidgetItem assocated with the given index .

PySide.QtGui.QTableWidget.itemPressed(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
PySide.QtGui.QTableWidget.itemPrototype()
Return type:PySide.QtGui.QTableWidgetItem

Returns the item prototype used by the table.

PySide.QtGui.QTableWidget.itemSelectionChanged()
PySide.QtGui.QTableWidget.items(data)
Parameters:dataPySide.QtCore.QMimeData
Return type:

Returns a list of pointers to the items contained in the data object. If the object was not created by a PySide.QtGui.QTreeWidget in the same process, the list is empty.

PySide.QtGui.QTableWidget.mimeData(items)
Parameters:items
Return type:PySide.QtCore.QMimeData
PySide.QtGui.QTableWidget.mimeTypes()
Return type:list of strings

Returns a list of MIME types that can be used to describe a list of tablewidget items.

PySide.QtGui.QTableWidget.openPersistentEditor(item)
Parameters:itemPySide.QtGui.QTableWidgetItem

Opens an editor for the give item . The editor remains open after editing.

PySide.QtGui.QTableWidget.removeCellWidget(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int

Removes the widget set on the cell indicated by row and column .

PySide.QtGui.QTableWidget.removeColumn(column)
Parameters:columnPySide.QtCore.int

Removes the column column and all its items from the table.

PySide.QtGui.QTableWidget.removeRow(row)
Parameters:rowPySide.QtCore.int

Removes the row row and all its items from the table.

PySide.QtGui.QTableWidget.row(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
Return type:PySide.QtCore.int

Returns the row for the item .

PySide.QtGui.QTableWidget.rowCount()
Return type:PySide.QtCore.int

This property holds the number of rows in the table.

By default, for a table constructed without row and column counts, this property contains a value of 0.

PySide.QtGui.QTableWidget.scrollToItem(item[, hint=EnsureVisible])
Parameters:
PySide.QtGui.QTableWidget.selectedItems()
Return type:

Returns a list of all selected items.

This function returns a list of pointers to the contents of the selected cells. Use the PySide.QtGui.QTableView.selectedIndexes() function to retrieve the complete selection including empty cells.

See also

PySide.QtGui.QTableView.selectedIndexes()

PySide.QtGui.QTableWidget.selectedRanges()
Return type:

Returns a list of all selected ranges.

PySide.QtGui.QTableWidget.setCellWidget(row, column, widget)
Parameters:

Sets the given widget to be displayed in the cell in the given row and column , passing the ownership of the widget to the table.

If cell widget A is replaced with cell widget B, cell widget A will be deleted. For example, in the code snippet below, the PySide.QtGui.QLineEdit object will be deleted.

setCellWidget(index, QLineEdit())
...
setCellWidget(index, QTextEdit())
PySide.QtGui.QTableWidget.setColumnCount(columns)
Parameters:columnsPySide.QtCore.int

This property holds the number of columns in the table.

By default, for a table constructed without row and column counts, this property contains a value of 0.

PySide.QtGui.QTableWidget.setCurrentCell(row, column, command)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
  • commandPySide.QtGui.QItemSelectionModel.SelectionFlags
PySide.QtGui.QTableWidget.setCurrentCell(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int

Sets the current cell to be the cell at position (row , column ).

Depending on the current selection mode , the cell may also be selected.

PySide.QtGui.QTableWidget.setCurrentItem(item)
Parameters:itemPySide.QtGui.QTableWidgetItem

Sets the current item to item .

Unless the selection mode is NoSelection , the item is also be selected.

PySide.QtGui.QTableWidget.setCurrentItem(item, command)
Parameters:
PySide.QtGui.QTableWidget.setHorizontalHeaderItem(column, item)
Parameters:

Sets the horizontal header item for column column to item .

PySide.QtGui.QTableWidget.setHorizontalHeaderLabels(labels)
Parameters:labels – list of strings

Sets the horizontal header labels using labels .

PySide.QtGui.QTableWidget.setItem(row, column, item)
Parameters:

Sets the item for the given row and column to item .

The table takes ownership of the item.

Note that if sorting is enabled (see PySide.QtGui.QTableView.sortingEnabled() ) and column is the current sort column, the row will be moved to the sorted position determined by item .

If you want to set several items of a particular row (say, by calling PySide.QtGui.QTableWidget.setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. PySide.QtGui.QTableWidget.setItem() will not move the row).

PySide.QtGui.QTableWidget.setItemPrototype(item)
Parameters:itemPySide.QtGui.QTableWidgetItem

Sets the item prototype for the table to the specified item .

The table widget will use the item prototype clone function when it needs to create a new table item. For example when the user is editing in an empty cell. This is useful when you have a PySide.QtGui.QTableWidgetItem subclass and want to make sure that PySide.QtGui.QTableWidget creates instances of your subclass.

The table takes ownership of the prototype.

PySide.QtGui.QTableWidget.setRangeSelected(range, select)
Parameters:

Selects or deselects the range depending on select .

PySide.QtGui.QTableWidget.setRowCount(rows)
Parameters:rowsPySide.QtCore.int

This property holds the number of rows in the table.

By default, for a table constructed without row and column counts, this property contains a value of 0.

PySide.QtGui.QTableWidget.setVerticalHeaderItem(row, item)
Parameters:

Sets the vertical header item for row row to item .

PySide.QtGui.QTableWidget.setVerticalHeaderLabels(labels)
Parameters:labels – list of strings

Sets the vertical header labels using labels .

PySide.QtGui.QTableWidget.sortItems(column[, order=Qt.AscendingOrder])
Parameters:
  • columnPySide.QtCore.int
  • orderPySide.QtCore.Qt.SortOrder
PySide.QtGui.QTableWidget.supportedDropActions()
Return type:PySide.QtCore.Qt.DropActions

Returns the drop actions supported by this view.

See also

Qt.DropActions

PySide.QtGui.QTableWidget.takeHorizontalHeaderItem(column)
Parameters:columnPySide.QtCore.int
Return type:PySide.QtGui.QTableWidgetItem

Removes the horizontal header item at column from the header without deleting it.

PySide.QtGui.QTableWidget.takeItem(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
Return type:

PySide.QtGui.QTableWidgetItem

Removes the item at row and column from the table without deleting it.

PySide.QtGui.QTableWidget.takeVerticalHeaderItem(row)
Parameters:rowPySide.QtCore.int
Return type:PySide.QtGui.QTableWidgetItem

Removes the vertical header item at row from the header without deleting it.

PySide.QtGui.QTableWidget.verticalHeaderItem(row)
Parameters:rowPySide.QtCore.int
Return type:PySide.QtGui.QTableWidgetItem

Returns the vertical header item for row row .

PySide.QtGui.QTableWidget.visualColumn(logicalColumn)
Parameters:logicalColumnPySide.QtCore.int
Return type:PySide.QtCore.int

Returns the visual column of the given logicalColumn .

PySide.QtGui.QTableWidget.visualItemRect(item)
Parameters:itemPySide.QtGui.QTableWidgetItem
Return type:PySide.QtCore.QRect

Returns the rectangle on the viewport occupied by the item at item .

PySide.QtGui.QTableWidget.visualRow(logicalRow)
Parameters:logicalRowPySide.QtCore.int
Return type:PySide.QtCore.int

Returns the visual row of the given logicalRow .