QTableWidgetclass provides an item-based table view with a default model. 更多 …
def
cellWidget
(row, column)
def
closePersistentEditor
(item)
def
column
(item)
def
columnCount
()
def
currentColumn
()
def
currentItem
()
def
currentRow
()
def
editItem
(item)
def
findItems
(text, flags)
def
horizontalHeaderItem
(column)
def
indexFromItem
(item)
def
indexFromItem
(item)
def
isItemSelected
(item)
def
isPersistentEditorOpen
(item)
def
item
(row, column)
def
itemAt
(p)
def
itemAt
(x, y)
def
itemFromIndex
(index)
def
itemPrototype
()
def
items
(data)
def
openPersistentEditor
(item)
def
removeCellWidget
(row, column)
def
row
(item)
def
rowCount
()
def
selectedItems
()
def
selectedRanges
()
def
setCellWidget
(row, column, widget)
def
setColumnCount
(columns)
def
setCurrentCell
(row, column)
def
setCurrentCell
(row, column, command)
def
setCurrentItem
(item)
def
setCurrentItem
(item, command)
def
setHorizontalHeaderItem
(column, item)
def
setHorizontalHeaderLabels
(labels)
def
setItem
(row, column, item)
def
setItemPrototype
(item)
def
setItemSelected
(item, select)
def
setRangeSelected
(range, select)
def
setRowCount
(rows)
def
setVerticalHeaderItem
(row, item)
def
setVerticalHeaderLabels
(labels)
def
sortItems
(column[, order=Qt.AscendingOrder])
def
takeHorizontalHeaderItem
(column)
def
takeItem
(row, column)
def
takeVerticalHeaderItem
(row)
def
verticalHeaderItem
(row)
def
visualColumn
(logicalColumn)
def
visualItemRect
(item)
def
visualRow
(logicalRow)
def
dropMimeData
(row, column, data, action)
def
mimeData
(items)
def
mimeTypes
()
def
supportedDropActions
()
def
clear
()
def
clearContents
()
def
insertColumn
(column)
def
insertRow
(row)
def
removeColumn
(column)
def
removeRow
(row)
def
scrollToItem
(item[, hint=EnsureVisible])
def
cellActivated
(row, column)
def
cellChanged
(row, column)
def
cellClicked
(row, column)
def
cellDoubleClicked
(row, column)
def
cellEntered
(row, column)
def
cellPressed
(row, column)
def
currentCellChanged
(currentRow, currentColumn, previousRow, previousColumn)
def
currentItemChanged
(current, previous)
def
itemActivated
(item)
def
itemChanged
(item)
def
itemClicked
(item)
def
itemDoubleClicked
(item)
def
itemEntered
(item)
def
itemPressed
(item)
def
itemSelectionChanged
()
![]()
Table widgets provide standard table display facilities for applications. The items in a
QTableWidgetare provided byQTableWidgetItem.若希望表格使用您自己的数据模型,应使用
QTableView而不是此类。可以采用所需行数和列数构造表格 Widget:
tableWidget = new QTableWidget(12, 3, this);另外,可以在不给定尺寸的情况下构建表格并稍后重置尺寸:
tableWidget = new QTableWidget(this); tableWidget->setRowCount(10); tableWidget->setColumnCount(5);Items are created outside the table (with no parent widget) and inserted into the table with
setItem():QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg( (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
setItem()了解细节)。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
setHorizontalHeaderLabels()andsetVerticalHeaderLabels()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:QTableWidgetItem *cubesHeaderItem = new 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
rowCount(), and the number of columns withcolumnCount(). The table can be cleared with theclear()函数。
QTableWidget
(
[
parent=None
]
)
¶
QTableWidget(rows, columns[, parent=None])
- param parent
- param columns
int- param rows
int
创建新的表格视图,采用给定
parent
.
创建新的表格视图,采用给定
rows
and
columns
,和采用给定
parent
.
PySide2.QtWidgets.QTableWidget.
cellActivated
(
row
,
column
)
¶
row
–
int
column
–
int
PySide2.QtWidgets.QTableWidget.
cellChanged
(
row
,
column
)
¶
row
–
int
column
–
int
PySide2.QtWidgets.QTableWidget.
cellClicked
(
row
,
column
)
¶
row
–
int
column
–
int
PySide2.QtWidgets.QTableWidget.
cellDoubleClicked
(
row
,
column
)
¶
row
–
int
column
–
int
PySide2.QtWidgets.QTableWidget.
cellEntered
(
row
,
column
)
¶
row
–
int
column
–
int
PySide2.QtWidgets.QTableWidget.
cellPressed
(
row
,
column
)
¶
row
–
int
column
–
int
PySide2.QtWidgets.QTableWidget.
cellWidget
(
row
,
column
)
¶
row
–
int
column
–
int
返回单元格显示 Widget,在给定
row
and
column
.
注意
表格拥有 Widget 的所有权。
另请参阅
PySide2.QtWidgets.QTableWidget.
clear
(
)
¶
Removes all items in the view. This will also remove all selections and headers. If you don’t want to remove the headers, use
clearContents()
. The table dimensions stay the same.
PySide2.QtWidgets.QTableWidget.
clearContents
(
)
¶
Removes all items not in the headers from the view. This will also remove all selections. The table dimensions stay the same.
PySide2.QtWidgets.QTableWidget.
closePersistentEditor
(
item
)
¶
item
–
QTableWidgetItem
关闭持久编辑器为
item
.
PySide2.QtWidgets.QTableWidget.
column
(
item
)
¶
item
–
QTableWidgetItem
int
返回列号为
item
.
PySide2.QtWidgets.QTableWidget.
columnCount
(
)
¶
int
返回列数。
另请参阅
PySide2.QtWidgets.QTableWidget.
currentCellChanged
(
currentRow
,
currentColumn
,
previousRow
,
previousColumn
)
¶
currentRow
–
int
currentColumn
–
int
previousRow
–
int
previousColumn
–
int
PySide2.QtWidgets.QTableWidget.
currentColumn
(
)
¶
int
返回当前项的列号。
PySide2.QtWidgets.QTableWidget.
currentItem
(
)
¶
返回当前项。
另请参阅
PySide2.QtWidgets.QTableWidget.
currentItemChanged
(
current
,
上一
)
¶
current
–
QTableWidgetItem
上一
–
QTableWidgetItem
PySide2.QtWidgets.QTableWidget.
currentRow
(
)
¶
int
返回当前项的行号。
PySide2.QtWidgets.QTableWidget.
dropMimeData
(
row
,
column
,
data
,
action
)
¶
row
–
int
column
–
int
data
–
QMimeData
action
–
DropAction
bool
处理
data
提供通过拖放操作结束按给定
action
以给定
row
and
column
。返回
true
if the data and action can be handled by the model; otherwise returns
false
.
PySide2.QtWidgets.QTableWidget.
editItem
(
item
)
¶
item
–
QTableWidgetItem
开始编辑
item
若它可编辑。
PySide2.QtWidgets.QTableWidget.
findItems
(
text
,
flags
)
¶
text – unicode
flags
–
MatchFlags
Finds items that matches the
text
using the given
flags
.
PySide2.QtWidgets.QTableWidget.
horizontalHeaderItem
(
column
)
¶
column
–
int
Returns the horizontal header item for column,
column
, if one has been set; otherwise returns
None
.
PySide2.QtWidgets.QTableWidget.
indexFromItem
(
item
)
¶
item
–
QTableWidgetItem
QModelIndex
返回
QModelIndex
关联给定
item
.
注意
In Qt versions prior to 5.10, this function took a non-
const
item
.
PySide2.QtWidgets.QTableWidget.
indexFromItem
(
item
)
¶
item
–
QTableWidgetItem
QModelIndex
返回
QModelIndex
关联给定
item
.
注意
In Qt versions prior to 5.10, this function took a non-
const
item
.
PySide2.QtWidgets.QTableWidget.
insertColumn
(
column
)
¶
column
–
int
把空列插入表格,位置
column
.
PySide2.QtWidgets.QTableWidget.
insertRow
(
row
)
¶
row
–
int
把空行插入表格,位置
row
.
PySide2.QtWidgets.QTableWidget.
isItemSelected
(
item
)
¶
item
–
QTableWidgetItem
bool
注意
此函数被弃用。
返回
true
若
item
is selected, otherwise returns
false
.
This function is deprecated. Use
isSelected()
代替。
PySide2.QtWidgets.QTableWidget.
isPersistentEditorOpen
(
item
)
¶
item
–
QTableWidgetItem
bool
返回是否打开持久编辑器为项
item
.
PySide2.QtWidgets.QTableWidget.
item
(
row
,
column
)
¶
row
–
int
column
–
int
返回项为给定
row
and
column
若有设置;否则返回
None
.
另请参阅
PySide2.QtWidgets.QTableWidget.
itemActivated
(
item
)
¶
item
–
QTableWidgetItem
PySide2.QtWidgets.QTableWidget.
itemAt
(
p
)
¶
p
–
QPoint
Returns a pointer to the item at the given
point
, or returns
None
if
point
is not covered by an item in the table widget.
另请参阅
PySide2.QtWidgets.QTableWidget.
itemAt
(
x
,
y
)
¶
x
–
int
y
–
int
Returns the item at the position equivalent to
QPoint
(
ax
,
ay
) in the table widget’s coordinate system, or returns
None
if the specified point is not covered by an item in the table widget.
另请参阅
PySide2.QtWidgets.QTableWidget.
itemChanged
(
item
)
¶
item
–
QTableWidgetItem
PySide2.QtWidgets.QTableWidget.
itemClicked
(
item
)
¶
item
–
QTableWidgetItem
PySide2.QtWidgets.QTableWidget.
itemDoubleClicked
(
item
)
¶
item
–
QTableWidgetItem
PySide2.QtWidgets.QTableWidget.
itemEntered
(
item
)
¶
item
–
QTableWidgetItem
PySide2.QtWidgets.QTableWidget.
itemFromIndex
(
index
)
¶
index
–
QModelIndex
返回指针指向
QTableWidgetItem
关联给定
index
.
PySide2.QtWidgets.QTableWidget.
itemPressed
(
item
)
¶
item
–
QTableWidgetItem
PySide2.QtWidgets.QTableWidget.
itemPrototype
(
)
¶
Returns the item prototype used by the table.
另请参阅
PySide2.QtWidgets.QTableWidget.
itemSelectionChanged
(
)
¶
PySide2.QtWidgets.QTableWidget.
items
(
data
)
¶
data
–
QMimeData
Returns a list of pointers to the items contained in the
data
object. If the object was not created by a
QTreeWidget
in the same process, the list is empty.
PySide2.QtWidgets.QTableWidget.
mimeData
(
items
)
¶
items –
QMimeData
返回对象包含序列化描述指定通过
items
。用于描述项的格式获取自
mimeTypes()
函数。
若项列表为空,
None
被返回而不是序列化空列表。
PySide2.QtWidgets.QTableWidget.
mimeTypes
(
)
¶
字符串列表
Returns a list of MIME types that can be used to describe a list of tablewidget items.
另请参阅
PySide2.QtWidgets.QTableWidget.
openPersistentEditor
(
item
)
¶
item
–
QTableWidgetItem
Opens an editor for the give
item
. The editor remains open after editing.
PySide2.QtWidgets.QTableWidget.
removeCellWidget
(
row
,
column
)
¶
row
–
int
column
–
int
Removes the widget set on the cell indicated by
row
and
column
.
PySide2.QtWidgets.QTableWidget.
removeColumn
(
column
)
¶
column
–
int
移除列
column
及表格中的所有项。
PySide2.QtWidgets.QTableWidget.
removeRow
(
row
)
¶
row
–
int
移除行
row
及表格中的所有项。
PySide2.QtWidgets.QTableWidget.
row
(
item
)
¶
item
–
QTableWidgetItem
int
Returns the row for the
item
.
PySide2.QtWidgets.QTableWidget.
rowCount
(
)
¶
int
Returns the number of rows.
另请参阅
PySide2.QtWidgets.QTableWidget.
scrollToItem
(
item
[
,
hint=EnsureVisible
]
)
¶
item
–
QTableWidgetItem
hint
–
ScrollHint
Scrolls the view if necessary to ensure that the
item
is visible. The
hint
parameter specifies more precisely where the
item
should be located after the operation.
PySide2.QtWidgets.QTableWidget.
selectedItems
(
)
¶
Returns a list of all selected items.
This function returns a list of pointers to the contents of the selected cells. Use the
selectedIndexes()
function to retrieve the complete selection
包括
empty cells.
另请参阅
selectedIndexes()
PySide2.QtWidgets.QTableWidget.
selectedRanges
(
)
¶
Returns a list of all selected ranges.
PySide2.QtWidgets.QTableWidget.
setCellWidget
(
row
,
column
,
widget
)
¶
row
–
int
column
–
int
widget
–
QWidget
设置给定
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
QLineEdit
object will be deleted.
setCellWidget(index, QLineEdit())
...
setCellWidget(index, QTextEdit())
另请参阅
PySide2.QtWidgets.QTableWidget.
setColumnCount
(
columns
)
¶
columns
–
int
Sets the number of columns in this table’s model to
columns
. If this is less than
columnCount()
, the data in the unwanted columns is discarded.
PySide2.QtWidgets.QTableWidget.
setCurrentCell
(
row
,
column
)
¶
row
–
int
column
–
int
Sets the current cell to be the cell at position (
row
,
column
).
Depending on the current
selection
mode
, the cell may also be selected.
PySide2.QtWidgets.QTableWidget.
setCurrentCell
(
row
,
column
,
command
)
¶
row
–
int
column
–
int
command
–
SelectionFlags
Sets the current cell to be the cell at position (
row
,
column
), using the given
command
.
PySide2.QtWidgets.QTableWidget.
setCurrentItem
(
item
)
¶
item
–
QTableWidgetItem
Sets the current item to
item
.
除非选定模式为
NoSelection
,项还被选中。
PySide2.QtWidgets.QTableWidget.
setCurrentItem
(
item
,
command
)
¶
item
–
QTableWidgetItem
command
–
SelectionFlags
Sets the current item to be
item
,使用给定
command
.
PySide2.QtWidgets.QTableWidget.
setHorizontalHeaderItem
(
column
,
item
)
¶
column
–
int
item
–
QTableWidgetItem
Sets the horizontal header item for column
column
to
item
. If necessary, the column count is increased to fit the item. The previous header item (if there was one) is deleted.
PySide2.QtWidgets.QTableWidget.
setHorizontalHeaderLabels
(
labels
)
¶
labels – 字符串列表
设置水平 Header 头标签,使用
labels
.
PySide2.QtWidgets.QTableWidget.
setItem
(
row
,
column
,
item
)
¶
row
–
int
column
–
int
item
–
QTableWidgetItem
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
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 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. will not move the row).
另请参阅
PySide2.QtWidgets.QTableWidget.
setItemPrototype
(
item
)
¶
item
–
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
QTableWidgetItem
subclass and want to make sure that
QTableWidget
creates instances of your subclass.
The table takes ownership of the prototype.
另请参阅
PySide2.QtWidgets.QTableWidget.
setItemSelected
(
item
,
select
)
¶
item
–
QTableWidgetItem
select
–
bool
注意
此函数被弃用。
Selects or deselects
item
depending on
select
.
This function is deprecated. Use
setSelected()
代替。
另请参阅
PySide2.QtWidgets.QTableWidget.
setRangeSelected
(
range
,
select
)
¶
range
–
QTableWidgetSelectionRange
select
–
bool
Selects or deselects the
range
depending on
select
.
PySide2.QtWidgets.QTableWidget.
setRowCount
(
rows
)
¶
rows
–
int
Sets the number of rows in this table’s model to
rows
. If this is less than
rowCount()
, the data in the unwanted rows is discarded.
PySide2.QtWidgets.QTableWidget.
setVerticalHeaderItem
(
row
,
item
)
¶
row
–
int
item
–
QTableWidgetItem
Sets the vertical header item for row
row
to
item
.
另请参阅
PySide2.QtWidgets.QTableWidget.
setVerticalHeaderLabels
(
labels
)
¶
labels – 字符串列表
Sets the vertical header labels using
labels
.
PySide2.QtWidgets.QTableWidget.
sortItems
(
column
[
,
order=Qt.AscendingOrder
]
)
¶
column
–
int
order
–
SortOrder
Sorts all the rows in the table widget based on
column
and
order
.
PySide2.QtWidgets.QTableWidget.
supportedDropActions
(
)
¶
DropActions
返回由此视图所支持的掉落动作。
另请参阅
DropActions
PySide2.QtWidgets.QTableWidget.
takeHorizontalHeaderItem
(
column
)
¶
column
–
int
Removes the horizontal header item at
column
从头部而不删除它。
PySide2.QtWidgets.QTableWidget.
takeItem
(
row
,
column
)
¶
row
–
int
column
–
int
移除项在
row
and
column
from the table without deleting it.
PySide2.QtWidgets.QTableWidget.
takeVerticalHeaderItem
(
row
)
¶
row
–
int
移除垂直 Header 头部项在
row
从头部而不删除它。
PySide2.QtWidgets.QTableWidget.
verticalHeaderItem
(
row
)
¶
row
–
int
Returns the vertical header item for row
row
.
PySide2.QtWidgets.QTableWidget.
visualColumn
(
logicalColumn
)
¶
logicalColumn
–
int
int
Returns the visual column of the given
logicalColumn
.
PySide2.QtWidgets.QTableWidget.
visualItemRect
(
item
)
¶
item
–
QTableWidgetItem
QRect
返回项所占据的视口矩形在
item
.
PySide2.QtWidgets.QTableWidget.
visualRow
(
logicalRow
)
¶
logicalRow
–
int
int
Returns the visual row of the given
logicalRow
.