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.
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
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 .
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|---|
Return type: |
Returns the widget displayed in the cell in the given row and column .
Note
The table takes ownership of the widget.
Removes all items in the view. This will also remove all selections. The table dimensions stay the same.
Removes all items not in the headers from the view. This will also remove all selections. The table dimensions stay the same.
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Closes the persistent editor for item .
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|---|
Return type: | PySide.QtCore.int |
Returns the column for the item .
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.
Parameters: |
|
---|
Return type: | PySide.QtCore.int |
---|
Returns the column of the current item.
Return type: | PySide.QtGui.QTableWidgetItem |
---|
Returns the current item.
Parameters: |
|
---|
Return type: | PySide.QtCore.int |
---|
Returns the row of the current item.
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Starts editing the item if it is editable.
Parameters: |
|
---|---|
Return type: |
Parameters: | column – PySide.QtCore.int |
---|---|
Return type: | PySide.QtGui.QTableWidgetItem |
Returns the horizontal header item for column, column , if one has been set; otherwise returns 0.
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|---|
Return type: | PySide.QtCore.QModelIndex |
Returns the PySide.QtCore.QModelIndex assocated with the given item .
Parameters: | column – PySide.QtCore.int |
---|
Inserts an empty column into the table at column .
Parameters: | row – PySide.QtCore.int |
---|
Inserts an empty row into the table at row .
Parameters: |
|
---|---|
Return type: |
Returns the item for the given row and column if one has been set; otherwise returns 0.
See also
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Parameters: |
|
---|---|
Return type: |
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.
See also
Parameters: | p – PySide.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.
See also
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Parameters: | index – PySide.QtCore.QModelIndex |
---|---|
Return type: | PySide.QtGui.QTableWidgetItem |
Returns a pointer to the PySide.QtGui.QTableWidgetItem assocated with the given index .
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Return type: | PySide.QtGui.QTableWidgetItem |
---|
Returns the item prototype used by the table.
Parameters: | data – PySide.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.
Parameters: | items – |
---|---|
Return type: | PySide.QtCore.QMimeData |
Return type: | list of strings |
---|
Returns a list of MIME types that can be used to describe a list of tablewidget items.
See also
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Opens an editor for the give item . The editor remains open after editing.
Parameters: |
|
---|
Removes the widget set on the cell indicated by row and column .
Parameters: | column – PySide.QtCore.int |
---|
Removes the column column and all its items from the table.
Parameters: | row – PySide.QtCore.int |
---|
Removes the row row and all its items from the table.
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|---|
Return type: | PySide.QtCore.int |
Returns the row for the item .
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.
Parameters: |
---|
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()
Return type: |
---|
Returns a list of all selected ranges.
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())
Parameters: | columns – 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.
Parameters: |
|
---|
Parameters: |
|
---|
Sets the current cell to be the cell at position (row , column ).
Depending on the current selection mode , the cell may also be selected.
Parameters: |
|
---|
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|
Sets the current item to item .
Unless the selection mode is NoSelection , the item is also be selected.
Parameters: |
|
---|
Sets the horizontal header item for column column to item .
Parameters: | labels – list of strings |
---|
Sets the horizontal header labels using labels .
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).
Parameters: | item – PySide.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.
Parameters: |
|
---|
Selects or deselects the range depending on select .
Parameters: | rows – 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.
Parameters: |
|
---|
Sets the vertical header item for row row to item .
Parameters: | labels – list of strings |
---|
Sets the vertical header labels using labels .
Parameters: |
|
---|
Return type: | PySide.QtCore.Qt.DropActions |
---|
Returns the drop actions supported by this view.
See also
Qt.DropActions
Parameters: | column – PySide.QtCore.int |
---|---|
Return type: | PySide.QtGui.QTableWidgetItem |
Removes the horizontal header item at column from the header without deleting it.
Parameters: |
|
---|---|
Return type: |
Removes the item at row and column from the table without deleting it.
Parameters: | row – PySide.QtCore.int |
---|---|
Return type: | PySide.QtGui.QTableWidgetItem |
Removes the vertical header item at row from the header without deleting it.
Parameters: | row – PySide.QtCore.int |
---|---|
Return type: | PySide.QtGui.QTableWidgetItem |
Returns the vertical header item for row row .
Parameters: | logicalColumn – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the visual column of the given logicalColumn .
Parameters: | item – PySide.QtGui.QTableWidgetItem |
---|---|
Return type: | PySide.QtCore.QRect |
Returns the rectangle on the viewport occupied by the item at item .
Parameters: | logicalRow – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the visual row of the given logicalRow .