内容表

上一话题

QTabWidget

下一话题

QTableWidget

QTableView

QTableView class provides a default model/view implementation of a table view. 更多

Inheritance diagram of PySide2.QtWidgets.QTableView

继承者: QTableWidget

概要

函数

详细描述

../../_images/windows-tableview.png

A 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.

QTableView class is one of the 模型/视图类 and is part of Qt’s 模型/视图框架 .

QTableView implements the interfaces defined by the QAbstractItemView 类以允许它显示提供数据,通过模型派生自 QAbstractItemModel 类。

视觉外观

表格拥有的垂直 Header 头部可以获得使用 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() 函数。

行和列可以被隐藏和展示采用 hideRow() , hideColumn() , showRow() ,和 showColumn() . They can be selected with selectRow() and selectColumn() . The table will show a grid depending on the showGrid 特性。

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() .

qtableview-resized1

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 stretchLastSection 特性。

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

坐标系统

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() columnAt() and columnViewportPosition() functions provide the equivalent conversion operations between x-coordinates and column indexes.

class QTableView ( [ parent=None ] )
param parent

QWidget

Constructs a table view with a parent to represent the data.

PySide2.QtWidgets.QTableView. clearSpans ( )

Removes all row and column spans in the table view.

另请参阅

setSpan()

PySide2.QtWidgets.QTableView. columnAt ( x )
参数

x int

返回类型

int

Returns the column in which the given x-coordinate, x ,在内容坐标中定位。

注意

This function returns -1 if the given coordinate is not valid (has no column).

另请参阅

rowAt()

PySide2.QtWidgets.QTableView. columnCountChanged ( oldCount , newCount )
参数
  • 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 .

PySide2.QtWidgets.QTableView. columnMoved ( column , oldIndex , newIndex )
参数
  • column int

  • oldIndex int

  • newIndex int

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 .

另请参阅

rowMoved()

PySide2.QtWidgets.QTableView. columnResized ( column , oldWidth , newWidth )
参数
  • column int

  • oldWidth int

  • newWidth int

调用此槽改变宽度为给定 column 。旧宽度的指定通过 oldWidth ,和新宽度通过 newWidth .

另请参阅

rowResized()

PySide2.QtWidgets.QTableView. columnSpan ( row , column )
参数
  • row int

  • column int

返回类型

int

Returns the column span of the table element at ( row , column )。默认为 1。

PySide2.QtWidgets.QTableView. columnViewportPosition ( column )
参数

column int

返回类型

int

Returns the x-coordinate in contents coordinates of the given column .

PySide2.QtWidgets.QTableView. columnWidth ( column )
参数

column int

返回类型

int

Returns the width of the given column .

PySide2.QtWidgets.QTableView. gridStyle ( )
返回类型

PenStyle

另请参阅

setGridStyle()

PySide2.QtWidgets.QTableView. hideColumn ( column )
参数

column int

隐藏给定 column .

PySide2.QtWidgets.QTableView. hideRow ( row )
参数

row int

隐藏给定 row .

PySide2.QtWidgets.QTableView. horizontalHeader ( )
返回类型

QHeaderView

Returns the table view’s horizontal header.

PySide2.QtWidgets.QTableView. isColumnHidden ( column )
参数

column int

返回类型

bool

返回 true 若给定 column 被隐藏;否则返回 false .

另请参阅

isRowHidden()

PySide2.QtWidgets.QTableView. isCornerButtonEnabled ( )
返回类型

bool

PySide2.QtWidgets.QTableView. isRowHidden ( row )
参数

row int

返回类型

bool

返回 true 若给定 row 被隐藏;否则返回 false .

另请参阅

isColumnHidden()

PySide2.QtWidgets.QTableView. isSortingEnabled ( )
返回类型

bool

PySide2.QtWidgets.QTableView. resizeColumnToContents ( column )
参数

column int

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

注意

Only visible columns will be resized. Reimplement sizeHintForColumn() to resize hidden columns as well.

PySide2.QtWidgets.QTableView. resizeColumnsToContents ( )

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

PySide2.QtWidgets.QTableView. resizeRowToContents ( row )
参数

row int

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

PySide2.QtWidgets.QTableView. resizeRowsToContents ( )

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

PySide2.QtWidgets.QTableView. rowAt ( y )
参数

y int

返回类型

int

返回行在给定 y 坐标 y ,在内容坐标中定位。

注意

此函数返回 -1 若给定坐标无效 (没有行)。

另请参阅

columnAt()

PySide2.QtWidgets.QTableView. rowCountChanged ( oldCount , newCount )
参数
  • 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 .

PySide2.QtWidgets.QTableView. rowHeight ( row )
参数

row int

返回类型

int

返回高度为给定 row .

PySide2.QtWidgets.QTableView. rowMoved ( row , oldIndex , newIndex )
参数
  • row int

  • oldIndex int

  • newIndex int

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 .

另请参阅

columnMoved()

PySide2.QtWidgets.QTableView. rowResized ( row , oldHeight , newHeight )
参数
  • 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 .

另请参阅

columnResized()

PySide2.QtWidgets.QTableView. rowSpan ( row , column )
参数
  • row int

  • column int

返回类型

int

Returns the row span of the table element at ( row , column )。默认为 1。

PySide2.QtWidgets.QTableView. rowViewportPosition ( row )
参数

row int

返回类型

int

Returns the y-coordinate in contents coordinates of the given row .

PySide2.QtWidgets.QTableView. selectColumn ( column )
参数

column int

选择给定 column in the table view if the current SelectionMode and SelectionBehavior allows columns to be selected.

另请参阅

selectRow()

PySide2.QtWidgets.QTableView. selectRow ( row )
参数

row int

选择给定 row in the table view if the current SelectionMode and SelectionBehavior allows rows to be selected.

另请参阅

selectColumn()

PySide2.QtWidgets.QTableView. setColumnHidden ( column , hide )
参数
  • column int

  • hide bool

hide is true the given column will be hidden; otherwise it will be shown.

PySide2.QtWidgets.QTableView. setColumnWidth ( column , width )
参数
  • column int

  • width int

设置宽度为给定 column to be width .

另请参阅

columnWidth()

PySide2.QtWidgets.QTableView. setCornerButtonEnabled ( enable )
参数

enable bool

PySide2.QtWidgets.QTableView. setGridStyle ( style )
参数

style PenStyle

另请参阅

gridStyle()

PySide2.QtWidgets.QTableView. setHorizontalHeader ( header )
参数

header QHeaderView

Sets the widget to use for the horizontal header to header .

PySide2.QtWidgets.QTableView. setRowHeight ( row , height )
参数
  • row int

  • height int

Sets the height of the given row to be height .

另请参阅

rowHeight()

PySide2.QtWidgets.QTableView. setRowHidden ( row , hide )
参数
  • row int

  • hide bool

hide is true row will be hidden, otherwise it will be shown.

PySide2.QtWidgets.QTableView. setShowGrid ( show )
参数

show bool

另请参阅

showGrid()

PySide2.QtWidgets.QTableView. setSortingEnabled ( enable )
参数

enable bool

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

PySide2.QtWidgets.QTableView. setSpan ( row , column , rowSpan , columnSpan )
参数
  • 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 ).

PySide2.QtWidgets.QTableView. setVerticalHeader ( header )
参数

header QHeaderView

Sets the widget to use for the vertical header to header .

PySide2.QtWidgets.QTableView. setWordWrap ( on )
参数

on bool

另请参阅

wordWrap()

PySide2.QtWidgets.QTableView. showColumn ( column )
参数

column int

Show the given column .

PySide2.QtWidgets.QTableView. showGrid ( )
返回类型

bool

另请参阅

setShowGrid()

PySide2.QtWidgets.QTableView. showRow ( row )
参数

row int

Show the given row .

PySide2.QtWidgets.QTableView. sortByColumn ( column )
参数

column int

注意

此函数被弃用。

这是重载函数。

This function is deprecated. Use sortByColumn (int column, SortOrder order) instead. Sorts the model by the values in the given column .

PySide2.QtWidgets.QTableView. sortByColumn ( column , order )
参数
  • column int

  • order SortOrder

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.

另请参阅

sortingEnabled

PySide2.QtWidgets.QTableView. verticalHeader ( )
返回类型

QHeaderView

Returns the table view’s vertical header.

PySide2.QtWidgets.QTableView. wordWrap ( )
返回类型

bool

另请参阅

setWordWrap()