QTableViewclass provides a default model/view implementation of a table view. 更多 …
继承者: QTableWidget
def
clearSpans
()
def
columnAt
(x)
def
columnSpan
(row, column)
def
columnViewportPosition
(column)
def
columnWidth
(column)
def
gridStyle
()
def
horizontalHeader
()
def
isColumnHidden
(column)
def
isCornerButtonEnabled
()
def
isRowHidden
(row)
def
isSortingEnabled
()
def
rowAt
(y)
def
rowHeight
(row)
def
rowSpan
(row, column)
def
rowViewportPosition
(row)
def
setColumnHidden
(column, hide)
def
setColumnWidth
(column, width)
def
setCornerButtonEnabled
(enable)
def
setGridStyle
(style)
def
setHorizontalHeader
(header)
def
setRowHeight
(row, height)
def
setRowHidden
(row, hide)
def
setSortingEnabled
(enable)
def
setSpan
(row, column, rowSpan, columnSpan)
def
setVerticalHeader
(header)
def
setWordWrap
(on)
def
showGrid
()
def
verticalHeader
()
def
wordWrap
()
def
columnCountChanged
(oldCount, newCount)
def
columnMoved
(column, oldIndex, newIndex)
def
columnResized
(column, oldWidth, newWidth)
def
hideColumn
(column)
def
hideRow
(row)
def
resizeColumnToContents
(column)
def
resizeColumnsToContents
()
def
resizeRowToContents
(row)
def
resizeRowsToContents
()
def
rowCountChanged
(oldCount, newCount)
def
rowMoved
(row, oldIndex, newIndex)
def
rowResized
(row, oldHeight, newHeight)
def
selectColumn
(column)
def
selectRow
(row)
def
setShowGrid
(show)
def
showColumn
(column)
def
showRow
(row)
def
sortByColumn
(column)
def
sortByColumn
(column, order)
![]()
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.
QTableViewclass is one of the 模型/视图类 and is part of Qt’s 模型/视图框架 .
QTableViewimplements the interfaces defined by theQAbstractItemView类以允许它显示提供数据,通过模型派生自QAbstractItemModel类。
表格拥有的垂直 Header 头部可以获得使用
verticalHeader()function, and a horizontal header that is available through thehorizontalHeader()function. The height of each row in the table can be found by usingrowHeight(); similarly, the width of columns can be found usingcolumnWidth(). Since both of these are plain widgets, you can hide either of them using theirhide()函数。行和列可以被隐藏和展示采用
hideRow(),hideColumn(),showRow(),和showColumn(). They can be selected withselectRow()andselectColumn(). The table will show a grid depending on theshowGrid特性。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 thesetIndexWidget()function, and later retrieved withindexWidget().
![]()
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()orverticalHeader()and set the header’sstretchLastSection特性。To distribute the available space according to the space requirement of each column or row, call the view’s
resizeColumnsToContents()orresizeRowsToContents()函数。
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 withrowViewportPosition()。columnAt()andcolumnViewportPosition()functions provide the equivalent conversion operations between x-coordinates and column indexes.另请参阅
QTableWidget视图类QAbstractItemModelQAbstractItemView图表范例 像素器范例 表格模型范例
QTableView
(
[
parent=None
]
)
¶
- param parent
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.
另请参阅
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).
另请参阅
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
.
另请参阅
PySide2.QtWidgets.QTableView.
columnResized
(
column
,
oldWidth
,
newWidth
)
¶
column
–
int
oldWidth
–
int
newWidth
–
int
调用此槽改变宽度为给定
column
。旧宽度的指定通过
oldWidth
,和新宽度通过
newWidth
.
另请参阅
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
另请参阅
PySide2.QtWidgets.QTableView.
hideColumn
(
column
)
¶
column
–
int
隐藏给定
column
.
另请参阅
PySide2.QtWidgets.QTableView.
hideRow
(
row
)
¶
row
–
int
隐藏给定
row
.
另请参阅
PySide2.QtWidgets.QTableView.
horizontalHeader
(
)
¶
Returns the table view’s horizontal header.
另请参阅
setHorizontalHeader()
verticalHeader()
headerData()
PySide2.QtWidgets.QTableView.
isColumnHidden
(
column
)
¶
column
–
int
bool
返回
true
若给定
column
被隐藏;否则返回
false
.
另请参阅
PySide2.QtWidgets.QTableView.
isCornerButtonEnabled
(
)
¶
bool
PySide2.QtWidgets.QTableView.
isRowHidden
(
row
)
¶
row
–
int
bool
返回
true
若给定
row
被隐藏;否则返回
false
.
另请参阅
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.
另请参阅
resizeColumnsToContents()
sizeHintForColumn()
resizeContentsPrecision()
PySide2.QtWidgets.QTableView.
resizeColumnsToContents
(
)
¶
Resizes all columns based on the size hints of the delegate used to render each item in the columns.
另请参阅
resizeColumnToContents()
sizeHintForColumn()
resizeContentsPrecision()
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.
另请参阅
resizeRowsToContents()
sizeHintForRow()
resizeContentsPrecision()
PySide2.QtWidgets.QTableView.
resizeRowsToContents
(
)
¶
Resizes all rows based on the size hints of the delegate used to render each item in the rows.
另请参阅
resizeRowToContents()
sizeHintForRow()
resizeContentsPrecision()
PySide2.QtWidgets.QTableView.
rowAt
(
y
)
¶
y
–
int
int
返回行在给定 y 坐标
y
,在内容坐标中定位。
注意
此函数返回 -1 若给定坐标无效 (没有行)。
另请参阅
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
.
另请参阅
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
.
另请参阅
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.
另请参阅
PySide2.QtWidgets.QTableView.
selectRow
(
row
)
¶
row
–
int
选择给定
row
in the table view if the current
SelectionMode
and
SelectionBehavior
allows rows to be selected.
另请参阅
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
.
另请参阅
PySide2.QtWidgets.QTableView.
setCornerButtonEnabled
(
enable
)
¶
enable
–
bool
PySide2.QtWidgets.QTableView.
setGridStyle
(
style
)
¶
style
–
PenStyle
另请参阅
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
.
另请参阅
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
另请参阅
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
另请参阅
PySide2.QtWidgets.QTableView.
showColumn
(
column
)
¶
column
–
int
Show the given
column
.
另请参阅
PySide2.QtWidgets.QTableView.
showGrid
(
)
¶
bool
另请参阅
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
(
)
¶
Returns the table view’s vertical header.
另请参阅
setVerticalHeader()
horizontalHeader()
headerData()
PySide2.QtWidgets.QTableView.
wordWrap
(
)
¶
bool
另请参阅