Inherited by: QTableWidget
The PySide.QtGui.QTableView class provides a default model/view implementation of a table view.
A PySide.QtGui.QTableView implements a table view that displays items from a model. This class is used to provide standard tables that were previously provided by the QTable class, but using the more flexible approach provided by Qt’s model/view architecture.
The PySide.QtGui.QTableView class is one of the Model/View Classes and is part of Qt’s model/view framework .
PySide.QtGui.QTableView implements the interfaces defined by the PySide.QtGui.QAbstractItemView class to allow it to display data provided by models derived from the PySide.QtCore.QAbstractItemModel class.
The table has a vertical header that can be obtained using the PySide.QtGui.QTableView.verticalHeader() function, and a horizontal header that is available through the PySide.QtGui.QTableView.horizontalHeader() function. The height of each row in the table can be found by using PySide.QtGui.QTableView.rowHeight() ; similarly, the width of columns can be found using PySide.QtGui.QTableView.columnWidth() . Since both of these are plain widgets, you can hide either of them using their PySide.QtGui.QWidget.hide() functions.
Rows and columns can be hidden and shown with PySide.QtGui.QTableView.hideRow() , PySide.QtGui.QTableView.hideColumn() , PySide.QtGui.QTableView.showRow() , and PySide.QtGui.QTableView.showColumn() . They can be selected with PySide.QtGui.QTableView.selectRow() and PySide.QtGui.QTableView.selectColumn() . The table will show a grid depending on the PySide.QtGui.QTableView.showGrid() property.
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 PySide.QtGui.QAbstractItemView.setIndexWidget() function, and later retrieved with PySide.QtGui.QAbstractItemView.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. Access the relevant header using PySide.QtGui.QTableView.horizontalHeader() or PySide.QtGui.QTableView.verticalHeader() and set the header’s PySide.QtGui.QHeaderView.stretchLastSection() property.
To distribute the available space according to the space requirement of each column or row, call the view’s PySide.QtGui.QTableView.resizeColumnsToContents() or PySide.QtGui.QTableView.resizeRowsToContents() functions.
For some specialized forms of tables it is useful to be able to convert between row and column indexes and widget coordinates. The PySide.QtGui.QTableView.rowAt() function provides the y-coordinate within the view of the specified row; the row index can be used to obtain a corresponding y-coordinate with PySide.QtGui.QTableView.rowViewportPosition() . The PySide.QtGui.QTableView.columnAt() and PySide.QtGui.QTableView.columnViewportPosition() functions provide the equivalent conversion operations between x-coordinates and column indexes.
PySide.QtGui.QTableView is styled appropriately for each platform. The following images show how it looks on three different platforms. Go to the Qt Widget Gallery to see its appearance in other styles.
A Windows XP style table view. A Macintosh style table view. A Plastique style table view. See also
PySide.QtGui.QTableWidget View Classes PySide.QtCore.QAbstractItemModel PySide.QtGui.QAbstractItemView Chart Example Pixelator Example Table Model Example
Parameters: | parent – PySide.QtGui.QWidget |
---|
Constructs a table view with a parent to represent the data.
See also
Removes all row and column spans in the table view.
See also
Parameters: | x – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the column in which the given x-coordinate, x , in contents coordinates is located.
Note
This function returns -1 if the given coordinate is not valid (has no column).
See also
Parameters: |
|
---|
This slot is called whenever columns are added or deleted. The previous number of columns is specified by oldCount , and the new number of columns is specified by newCount .
Parameters: |
|
---|
This slot is called to change the index of the given column in the table view. The old index is specified by oldIndex , and the new index by newIndex .
See also
Parameters: |
|
---|
This slot is called to change the width of the given column . The old width is specified by oldWidth , and the new width by newWidth .
See also
Parameters: |
|
---|---|
Return type: | PySide.QtCore.int |
Returns the column span of the table element at (row , column ). The default is 1.
Parameters: | column – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the x-coordinate in contents coordinates of the given column .
Parameters: | column – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the width of the given column .
Return type: | PySide.QtCore.Qt.PenStyle |
---|
This property holds the pen style used to draw the grid..
This property holds the style used when drawing the grid (see PySide.QtGui.QTableView.showGrid() ).
Parameters: | column – PySide.QtCore.int |
---|
Hide the given column .
Parameters: | row – PySide.QtCore.int |
---|
Hide the given row .
Return type: | PySide.QtGui.QHeaderView |
---|
Returns the table view’s horizontal header.
See also
PySide.QtGui.QTableView.setHorizontalHeader() PySide.QtGui.QTableView.verticalHeader() QAbstractItemModel.headerData()
Parameters: | column – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if the given column is hidden; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
This property holds whether the button in the top-left corner is enabled.
If this property is true then button in the top-left corner of the table view is enabled. Clicking on this button will select all the cells in the table view.
This property is true by default.
Parameters: | row – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if the given row is hidden; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
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 PySide.QtGui.QTableView.setSortingEnabled() immediately triggers a call to PySide.QtGui.QTableView.sortByColumn() with the current sort section and order.
Parameters: | column – PySide.QtCore.int |
---|
Resizes the given column based on the size hints of the delegate used to render each item in the column.
Note
Only visible columns will be resized. Reimplement PySide.QtGui.QTableView.sizeHintForColumn() to resize hidden columns as well.
Resizes all columns based on the size hints of the delegate used to render each item in the columns.
Parameters: | row – PySide.QtCore.int |
---|
Resizes the given row based on the size hints of the delegate used to render each item in the row.
Resizes all rows based on the size hints of the delegate used to render each item in the rows.
Parameters: | y – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the row in which the given y-coordinate, y , in contents coordinates is located.
Note
This function returns -1 if the given coordinate is not valid (has no row).
See also
Parameters: |
|
---|
This slot is called whenever rows are added or deleted. The previous number of rows is specified by oldCount , and the new number of rows is specified by newCount .
Parameters: | row – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the height of the given row .
Parameters: |
|
---|
This slot is called to change the index of the given row in the table view. The old index is specified by oldIndex , and the new index by newIndex .
Parameters: |
|
---|
This slot is called to change the height of the given row . The old height is specified by oldHeight , and the new height by newHeight .
Parameters: |
|
---|---|
Return type: | PySide.QtCore.int |
Returns the row span of the table element at (row , column ). The default is 1.
Parameters: | row – PySide.QtCore.int |
---|---|
Return type: | PySide.QtCore.int |
Returns the y-coordinate in contents coordinates of the given row .
Parameters: | column – PySide.QtCore.int |
---|
Selects the given column in the table view if the current QAbstractItemView.SelectionMode and QAbstractItemView.SelectionBehavior allows columns to be selected.
See also
Parameters: | row – PySide.QtCore.int |
---|
Selects the given row in the table view if the current QAbstractItemView.SelectionMode and QAbstractItemView.SelectionBehavior allows rows to be selected.
Parameters: |
|
---|
If hide is true the given column will be hidden; otherwise it will be shown.
Parameters: |
|
---|
Sets the width of the given column to be width .
Parameters: | enable – PySide.QtCore.bool |
---|
This property holds whether the button in the top-left corner is enabled.
If this property is true then button in the top-left corner of the table view is enabled. Clicking on this button will select all the cells in the table view.
This property is true by default.
Parameters: | style – PySide.QtCore.Qt.PenStyle |
---|
This property holds the pen style used to draw the grid..
This property holds the style used when drawing the grid (see PySide.QtGui.QTableView.showGrid() ).
Parameters: | header – PySide.QtGui.QHeaderView |
---|
Sets the widget to use for the horizontal header to header .
Parameters: |
|
---|
Sets the height of the given row to be height .
See also
Parameters: |
|
---|
If hide is true row will be hidden, otherwise it will be shown.
Parameters: | show – PySide.QtCore.bool |
---|
This property holds whether the grid is shown.
If this property is true a grid is drawn for the table; if the property is false, no grid is drawn. The default value is true.
Parameters: | enable – PySide.QtCore.bool |
---|
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 PySide.QtGui.QTableView.setSortingEnabled() immediately triggers a call to PySide.QtGui.QTableView.sortByColumn() with the current sort section and order.
Parameters: |
|
---|
Sets the span of the table element at (row , column ) to the number of rows and columns specified by (rowSpanCount , columnSpanCount ).
Parameters: | header – PySide.QtGui.QHeaderView |
---|
Sets the widget to use for the vertical header to header .
Parameters: | on – PySide.QtCore.bool |
---|
This property holds the item text word-wrapping policy.
If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is true by default.
Note that even of wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current PySide.QtGui.QAbstractItemView.textElideMode() .
Parameters: | column – PySide.QtCore.int |
---|
Show the given column .
Return type: | PySide.QtCore.bool |
---|
This property holds whether the grid is shown.
If this property is true a grid is drawn for the table; if the property is false, no grid is drawn. The default value is true.
Parameters: | row – PySide.QtCore.int |
---|
Show the given row .
Parameters: |
|
---|
Return type: | PySide.QtGui.QHeaderView |
---|
Returns the table view’s vertical header.
See also
PySide.QtGui.QTableView.setVerticalHeader() PySide.QtGui.QTableView.horizontalHeader() QAbstractItemModel.headerData()
Parameters: | index – PySide.QtCore.QModelIndex |
---|---|
Return type: | PySide.QtCore.int |
Return type: | PySide.QtCore.bool |
---|
This property holds the item text word-wrapping policy.
If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is true by default.
Note that even of wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current PySide.QtGui.QAbstractItemView.textElideMode() .