PySide6.QtWidgets.QTableView¶
- class QTableView¶
- The - QTableViewclass provides a default model/view implementation of a table view. More…- Inherited by: - QTableWidget- Synopsis¶- Properties¶- cornerButtonEnabledᅟ- Whether the button in the top-left corner is enabled
- gridStyleᅟ- The pen style used to draw the grid
- showGridᅟ- Whether the grid is shown
- sortingEnabledᅟ- Whether sorting is enabled
- wordWrapᅟ- The item text word-wrapping policy
 - Methods¶- def - __init__()
- def - clearSpans()
- def - columnAt()
- def - columnSpan()
- def - columnWidth()
- def - gridStyle()
- def - isColumnHidden()
- def - isRowHidden()
- def - rowAt()
- def - rowHeight()
- def - rowSpan()
- def - setColumnWidth()
- def - setGridStyle()
- def - setRowHeight()
- def - setRowHidden()
- def - setSpan()
- def - setWordWrap()
- def - showGrid()
- def - verticalHeader()
- def - wordWrap()
 - Slots¶
- def - columnMoved()
- def - columnResized()
- def - hideColumn()
- def - hideRow()
- def - rowMoved()
- def - rowResized()
- def - selectColumn()
- def - selectRow()
- def - setShowGrid()
- def - showColumn()
- def - showRow()
- def - sortByColumn()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶  - A - QTableViewimplements 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 - QTableViewclass is one of the Model/View Classes and is part of Qt’s model/view framework .- QTableViewimplements the interfaces defined by the- QAbstractItemViewclass to allow it to display data provided by models derived from the QAbstractItemModel class.- 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 found by using- rowHeight(); similarly, the width of columns can be found using- columnWidth(). Since both of these are plain widgets, you can hide either of them using their- hide()functions. Each header is configured with its- highlightSectionsand- sectionsClickableproperties set to- true.- Rows and columns can be hidden and shown with - hideRow(),- hideColumn(),- showRow(), and- showColumn(). They can be selected with- selectRow()and- selectColumn(). The table will show a grid depending on the- showGridproperty.- 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. Access the relevant header using - horizontalHeader()or- verticalHeader()and set the header’s- stretchLastSectionproperty.- To distribute the available space according to the space requirement of each column or row, call the view’s - resizeColumnsToContents()or- resizeRowsToContents()functions.- Coordinate Systems¶- For some specialized forms of tables it is useful to be able to convert between row and column indexes and widget coordinates. The - 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- rowViewportPosition(). The- columnAt()and- columnViewportPosition()functions provide the equivalent conversion operations between x-coordinates and column indexes.- See also - QTableWidgetView Classes- QAbstractItemView- Table Model Example- Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property cornerButtonEnabledᅟ: bool¶
 - This property holds whether the button in the top-left corner is enabled. - If this property is - truethen 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 - trueby default.- Access functions:
 - property gridStyleᅟ: Qt.PenStyle¶
 - This property holds the pen style used to draw the grid.. - This property holds the style used when drawing the grid (see - showGrid).- Access functions:
 - property showGridᅟ: bool¶
 - This property holds whether the grid is shown. - If this property is - truea grid is drawn for the table; if the property is- false, no grid is drawn. The default value is true.- Access functions:
 - property sortingEnabledᅟ: 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 - setSortingEnabled()immediately triggers a call to- sortByColumn()with the current sort section and order.- See also - Access functions:
 - property wordWrapᅟ: bool¶
 - This property holds the item text word-wrapping policy. - If this property is - truethen the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is- trueby 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 - textElideMode.- Access functions:
 - Constructs a table view with a - parentto represent the data.- See also - clearSpans()¶
 - Removes all row and column spans in the table view. - See also - columnAt(x)¶
- Parameters:
- x – int 
- Return type:
- 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 - columnCountChanged(oldCount, newCount)¶
- Parameters:
- oldCount – int 
- newCount – int 
 
 
 - 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.- columnMoved(column, oldIndex, newIndex)¶
- Parameters:
- column – int 
- oldIndex – int 
- newIndex – int 
 
 
 - This slot is called to change the index of the given - columnin the table view. The old index is specified by- oldIndex, and the new index by- newIndex.- See also - columnResized(column, oldWidth, newWidth)¶
- Parameters:
- column – int 
- oldWidth – int 
- newWidth – int 
 
 
 - 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 - columnSpan(row, column)¶
- Parameters:
- row – int 
- column – int 
 
- Return type:
- int 
 
 - Returns the column span of the table element at ( - row,- column). The default is 1.- columnViewportPosition(column)¶
- Parameters:
- column – int 
- Return type:
- int 
 
 - Returns the x-coordinate in contents coordinates of the given - column.- columnWidth(column)¶
- Parameters:
- column – int 
- Return type:
- int 
 
 - Returns the width of the given - column.- gridStyle()¶
- Return type:
 - See also 
 - Getter of property - gridStyleᅟ.- hideColumn(column)¶
- Parameters:
- column – int 
 
 - Hide the given - column.- See also - hideRow(row)¶
- Parameters:
- row – int 
 
 - Hide the given - row.- See also - horizontalHeader()¶
- Return type:
 
 - Returns the table view’s horizontal header. - isColumnHidden(column)¶
- Parameters:
- column – int 
- Return type:
- bool 
 
 - Returns - trueif the given- columnis hidden; otherwise returns- false.- See also - isCornerButtonEnabled()¶
- Return type:
- bool 
 
 - Getter of property - cornerButtonEnabledᅟ.- isRowHidden(row)¶
- Parameters:
- row – int 
- Return type:
- bool 
 
 - Returns - trueif the given- rowis hidden; otherwise returns- false.- See also - isSortingEnabled()¶
- Return type:
- bool 
 
 - Getter of property - sortingEnabledᅟ.- resizeColumnToContents(column)¶
- Parameters:
- column – int 
 
 - Resizes the given - columnbased on the size hints of the delegate used to render each item in the column.- Note - Only visible columns will be resized. Reimplement - sizeHintForColumn()to resize hidden columns as well.- See also - resizeColumnsToContents()- sizeHintForColumn()- resizeContentsPrecision()- resizeColumnsToContents()¶
 - Resizes all columns based on the size hints of the delegate used to render each item in the columns. - See also - resizeColumnToContents()- sizeHintForColumn()- resizeContentsPrecision()- resizeRowToContents(row)¶
- Parameters:
- row – int 
 
 - Resizes the given - rowbased on the size hints of the delegate used to render each item in the row.- See also - resizeRowsToContents()- sizeHintForRow()- resizeContentsPrecision()- resizeRowsToContents()¶
 - Resizes all rows based on the size hints of the delegate used to render each item in the rows. - See also - resizeRowToContents()- sizeHintForRow()- resizeContentsPrecision()- rowAt(y)¶
- Parameters:
- y – int 
- Return type:
- 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 - rowCountChanged(oldCount, newCount)¶
- Parameters:
- oldCount – int 
- newCount – int 
 
 
 - 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.- rowHeight(row)¶
- Parameters:
- row – int 
- Return type:
- int 
 
 - Returns the height of the given - row.- rowMoved(row, oldIndex, newIndex)¶
- Parameters:
- row – int 
- oldIndex – int 
- newIndex – int 
 
 
 - This slot is called to change the index of the given - rowin the table view. The old index is specified by- oldIndex, and the new index by- newIndex.- See also - rowResized(row, oldHeight, newHeight)¶
- Parameters:
- row – int 
- oldHeight – int 
- newHeight – int 
 
 
 - 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.- See also - rowSpan(row, column)¶
- Parameters:
- row – int 
- column – int 
 
- Return type:
- int 
 
 - Returns the row span of the table element at ( - row,- column). The default is 1.- See also - rowViewportPosition(row)¶
- Parameters:
- row – int 
- Return type:
- int 
 
 - Returns the y-coordinate in contents coordinates of the given - row.- selectColumn(column)¶
- Parameters:
- column – int 
 
 - Selects the given - columnin the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.- See also - selectRow(row)¶
- Parameters:
- row – int 
 
 - Selects the given - rowin the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.- See also - setColumnHidden(column, hide)¶
- Parameters:
- column – int 
- hide – bool 
 
 
 - If - hideis true the given- columnwill be hidden; otherwise it will be shown.- See also - setColumnWidth(column, width)¶
- Parameters:
- column – int 
- width – int 
 
 
 - Sets the width of the given - columnto be- width.- See also - setCornerButtonEnabled(enable)¶
- Parameters:
- enable – bool 
 - See also 
 - Setter of property - cornerButtonEnabledᅟ.- Setter of property - gridStyleᅟ.- setHorizontalHeader(header)¶
- Parameters:
- header – - QHeaderView
 
 - Sets the widget to use for the horizontal header to - header.- See also - setRowHeight(row, height)¶
- Parameters:
- row – int 
- height – int 
 
 
 - Sets the height of the given - rowto be- height.- See also - setRowHidden(row, hide)¶
- Parameters:
- row – int 
- hide – bool 
 
 
 - If - hideis true- rowwill be hidden, otherwise it will be shown.- See also - setShowGrid(show)¶
- Parameters:
- show – bool 
 - See also 
 - Setter of property - showGridᅟ.- setSortingEnabled(enable)¶
- Parameters:
- enable – bool 
 
 - If - enableis true, enables sorting for the table and immediately trigger a call to- sortByColumn()with the current sort section and order- See also - Setter of property - sortingEnabledᅟ.- setSpan(row, column, rowSpan, columnSpan)¶
- Parameters:
- row – int 
- column – int 
- rowSpan – int 
- columnSpan – int 
 
 
 - Sets the span of the table element at ( - row,- column) to the number of rows and columns specified by (- rowSpanCount,- columnSpanCount).- See also - setVerticalHeader(header)¶
- Parameters:
- header – - QHeaderView
 
 - Sets the widget to use for the vertical header to - header.- See also - setWordWrap(on)¶
- Parameters:
- on – bool 
 - See also 
 - Setter of property - wordWrapᅟ.- showColumn(column)¶
- Parameters:
- column – int 
 
 - Show the given - column.- See also - showGrid()¶
- Return type:
- bool 
 - See also 
 - Getter of property - showGridᅟ.- showRow(row)¶
- Parameters:
- row – int 
 
 - Show the given - row.- See also - Sorts the model by the values in the given - columnand- order.- columnmay 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.- See also - sortingEnabled- verticalHeader()¶
- Return type:
 
 - Returns the table view’s vertical header. - wordWrap()¶
- Return type:
- bool 
 - See also 
 - Getter of property - wordWrapᅟ.