继承者: QHelpContentWidget , QTreeWidget
def
allColumnsShowFocus
()
def
autoExpandDelay
()
def
columnAt
(x)
def
columnViewportPosition
(column)
def
columnWidth
(column)
def
drawTree
(painter, region)
def
expandsOnDoubleClick
()
def
header
()
def
indentation
()
def
indexAbove
(index)
def
indexBelow
(index)
def
indexRowSizeHint
(index)
def
isAnimated
()
def
isColumnHidden
(column)
def
isExpanded
(index)
def
isFirstColumnSpanned
(row, parent)
def
isHeaderHidden
()
def
isRowHidden
(row, parent)
def
isSortingEnabled
()
def
itemsExpandable
()
def
resetIndentation
()
def
rootIsDecorated
()
def
rowHeight
(index)
def
setAllColumnsShowFocus
(enable)
def
setAnimated
(enable)
def
setAutoExpandDelay
(delay)
def
setColumnHidden
(column, hide)
def
setColumnWidth
(column, width)
def
setExpanded
(index, expand)
def
setExpandsOnDoubleClick
(enable)
def
setFirstColumnSpanned
(row, parent, span)
def
setHeader
(header)
def
setHeaderHidden
(hide)
def
setIndentation
(i)
def
setItemsExpandable
(enable)
def
setRootIsDecorated
(show)
def
setRowHidden
(row, parent, hide)
def
setSortingEnabled
(enable)
def
setTreePosition
(logicalIndex)
def
setUniformRowHeights
(uniform)
def
setWordWrap
(on)
def
treePosition
()
def
uniformRowHeights
()
def
wordWrap
()
def
drawBranches
(painter, rect, index)
def
drawRow
(painter, options, index)
def
collapse
(index)
def
collapseAll
()
def
columnCountChanged
(oldCount, newCount)
def
columnMoved
()
def
columnResized
(column, oldSize, newSize)
def
expand
(index)
def
expandAll
()
def
expandRecursively
(index[, depth=-1])
def
expandToDepth
(depth)
def
hideColumn
(column)
def
reexpand
()
def
resizeColumnToContents
(column)
def
rowsRemoved
(parent, first, last)
def
showColumn
(column)
def
sortByColumn
(column)
def
sortByColumn
(column, order)
![]()
A
QTreeViewimplements a tree representation of items from a model. This class is used to provide standard hierarchical lists that were previously provided by theQListViewclass, but using the more flexible approach provided by Qt’s model/view architecture.
QTreeViewclass is one of the 模型/视图类 and is part of Qt’s 模型/视图框架 .
QTreeViewimplements the interfaces defined by theQAbstractItemView类以允许它显示提供数据,通过模型派生自QAbstractItemModel类。构建树视图以显示来自模型的数据很简单。在以下范例中,目录内容的提供通过
QFileSystemModel并作为树显示:model = QFileSystemModel() model.setRootPath(QDir.currentPath()) tree = QTreeView() tree.setModel(model)模型/视图体系结构确保树视图内容随模型改变更新。
拥有子级的项可以处于展开 (子级可见) 或折叠 (子级被隐藏) 状态。当此状态改变
collapsed()orexpanded()signal is emitted with the model index of the relevant item.用于指示层次结构级别缩进量的控制通过
indentation特性。树视图 Header 头部的构造使用
QHeaderView类且可以被隐藏使用header()->hide()。注意,每个 Header 头部的配置采用其stretchLastSection特性被设为 true,确保视图不浪费为 Header 头部赋值的任何空间。若此值被设为 true,此特性将覆盖 Header 头部最后区间设置的重置尺寸模式。默认情况下,树视图的所有列是可移动的,除第一列外。要禁用这些列的移动,使用
QHeaderView‘ssetSectionsMovable()函数。有关重新排列区间的更多信息,见Moving Header Sections.
QTreeViewsupports a set of key bindings that enable the user to navigate in the view and interact with the contents of items:
Key
Action
Up
将光标移动到上一行相同列项。若当前项父级没有更多行可导航,光标将移动到父级之前最后同级行相关项。
Down
Moves the cursor to the item in the same column on the next row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the first row of the sibling that follows the parent.
Left
通过折叠分支隐藏当前项 (若存在) 子级。
Minus
如同 Left。
Right
通过展开分支展现当前项 (若存在) 子级。
Plus
如同 Right。
星号
展开当前项及其所有子级 (若存在)。
PageUp
上移光标一页。
PageDown
下移光标一页。
首页
Moves the cursor to an item in the same column of the first row of the first top-level item in the model.
End
Moves the cursor to an item in the same column of the last row of the last top-level item in the model.
F2
In editable models, this opens the current item for editing. The Escape key can be used to cancel the editing process and revert any changes to the data displayed.
It is possible to give the view hints about the data it is handling in order to improve its performance when displaying large numbers of items. One approach that can be taken for views that are intended to display items with equal heights is to set the
uniformRowHeightsproperty to true.
QTreeView
(
[
parent=None
]
)
¶
- param parent
构造树视图采用
parent
to represent a model’s data. Use
setModel()
to set the model.
另请参阅
PySide2.QtWidgets.QTreeView.
allColumnsShowFocus
(
)
¶
bool
PySide2.QtWidgets.QTreeView.
autoExpandDelay
(
)
¶
int
另请参阅
PySide2.QtWidgets.QTreeView.
collapse
(
index
)
¶
index
–
QModelIndex
折叠的模型项指定通过
index
.
另请参阅
PySide2.QtWidgets.QTreeView.
collapseAll
(
)
¶
折叠所有展开项。
PySide2.QtWidgets.QTreeView.
collapsed
(
index
)
¶
index
–
QModelIndex
PySide2.QtWidgets.QTreeView.
columnAt
(
x
)
¶
x
–
int
int
Returns the column in the tree view whose header covers the
x
coordinate given.
PySide2.QtWidgets.QTreeView.
columnCountChanged
(
oldCount
,
newCount
)
¶
oldCount
–
int
newCount
–
int
Informs the tree view that the number of columns in the tree view has changed from
oldCount
to
newCount
.
PySide2.QtWidgets.QTreeView.
columnMoved
(
)
¶
This slot is called whenever a column has been moved.
PySide2.QtWidgets.QTreeView.
columnResized
(
column
,
oldSize
,
newSize
)
¶
column
–
int
oldSize
–
int
newSize
–
int
This function is called whenever
column
‘s size is changed in the header.
oldSize
and
newSize
give the previous size and the new size in pixels.
另请参阅
PySide2.QtWidgets.QTreeView.
columnViewportPosition
(
column
)
¶
column
–
int
int
Returns the horizontal position of the
column
in the viewport.
PySide2.QtWidgets.QTreeView.
columnWidth
(
column
)
¶
column
–
int
int
返回宽度为
column
.
PySide2.QtWidgets.QTreeView.
drawBranches
(
painter
,
rect
,
index
)
¶
painter
–
QPainter
rect
–
QRect
index
–
QModelIndex
Draws the branches in the tree view on the same row as the model item
index
,使用
painter
given. The branches are drawn in the rectangle specified by
rect
.
PySide2.QtWidgets.QTreeView.
drawRow
(
painter
,
options
,
index
)
¶
painter
–
QPainter
options
–
QStyleOptionViewItem
index
–
QModelIndex
Draws the row in the tree view that contains the model item
index
,使用
painter
given. The
option
controls how the item is displayed.
PySide2.QtWidgets.QTreeView.
drawTree
(
painter
,
region
)
¶
painter
–
QPainter
region
–
QRegion
Draws the part of the tree intersecting the given
region
使用指定
painter
.
另请参阅
paintEvent()
PySide2.QtWidgets.QTreeView.
expand
(
index
)
¶
index
–
QModelIndex
Expands the model item specified by the
index
.
另请参阅
PySide2.QtWidgets.QTreeView.
expandAll
(
)
¶
展开所有可展开项。
警告
: if the model contains a large number of items, this function will take some time to execute.
PySide2.QtWidgets.QTreeView.
expandRecursively
(
index
[
,
depth=-1
]
)
¶
index
–
QModelIndex
depth
–
int
Expands the item at the given
index
and all its children to the given
depth
。
depth
is relative to the given
index
. A
depth
of -1 will expand all children, a
depth
of 0 will only expand the given
index
.
警告
: if the model contains a large number of items, this function will take some time to execute.
另请参阅
PySide2.QtWidgets.QTreeView.
expandToDepth
(
depth
)
¶
depth
–
int
展开所有可展开项到给定
depth
.
PySide2.QtWidgets.QTreeView.
expanded
(
index
)
¶
index
–
QModelIndex
PySide2.QtWidgets.QTreeView.
expandsOnDoubleClick
(
)
¶
bool
PySide2.QtWidgets.QTreeView.
header
(
)
¶
返回用于树视图的 Header 头。
另请参阅
setHeader()
headerData()
PySide2.QtWidgets.QTreeView.
hideColumn
(
column
)
¶
column
–
int
隐藏
column
给定。
注意
This function should only be called after the model has been initialized, as the view needs to know the number of columns in order to hide
column
.
PySide2.QtWidgets.QTreeView.
indentation
(
)
¶
int
另请参阅
PySide2.QtWidgets.QTreeView.
indexAbove
(
index
)
¶
index
–
QModelIndex
QModelIndex
Returns the model index of the item above
index
.
PySide2.QtWidgets.QTreeView.
indexBelow
(
index
)
¶
index
–
QModelIndex
QModelIndex
Returns the model index of the item below
index
.
PySide2.QtWidgets.QTreeView.
indexRowSizeHint
(
index
)
¶
index
–
QModelIndex
int
Returns the size hint for the row indicated by
index
.
另请参阅
sizeHintForColumn()
uniformRowHeights()
PySide2.QtWidgets.QTreeView.
isAnimated
(
)
¶
bool
PySide2.QtWidgets.QTreeView.
isColumnHidden
(
column
)
¶
column
–
int
bool
返回
true
若
column
被隐藏;否则返回
false
.
PySide2.QtWidgets.QTreeView.
isExpanded
(
index
)
¶
index
–
QModelIndex
bool
返回
true
若模型项
index
被展开;否则返回 false。
PySide2.QtWidgets.QTreeView.
isFirstColumnSpanned
(
row
,
parent
)
¶
row
–
int
parent
–
QModelIndex
bool
返回
true
若第一列中的项在给定
row
的
parent
跨越所有列;否则返回
false
.
PySide2.QtWidgets.QTreeView.
isHeaderHidden
(
)
¶
bool
PySide2.QtWidgets.QTreeView.
isRowHidden
(
row
,
parent
)
¶
row
–
int
parent
–
QModelIndex
bool
返回
true
若项在给定
row
的
parent
被隐藏;否则返回
false
.
PySide2.QtWidgets.QTreeView.
isSortingEnabled
(
)
¶
bool
PySide2.QtWidgets.QTreeView.
itemsExpandable
(
)
¶
bool
另请参阅
PySide2.QtWidgets.QTreeView.
reexpand
(
)
¶
PySide2.QtWidgets.QTreeView.
resetIndentation
(
)
¶
PySide2.QtWidgets.QTreeView.
resizeColumnToContents
(
column
)
¶
column
–
int
重置尺寸
column
given to the size of its contents.
另请参阅
columnWidth()
setColumnWidth()
sizeHintForColumn()
resizeContentsPrecision()
PySide2.QtWidgets.QTreeView.
rootIsDecorated
(
)
¶
bool
另请参阅
PySide2.QtWidgets.QTreeView.
rowHeight
(
index
)
¶
index
–
QModelIndex
int
返回指示行的高度通过给定
index
.
另请参阅
PySide2.QtWidgets.QTreeView.
rowsRemoved
(
parent
,
first
,
last
)
¶
parent
–
QModelIndex
first
–
int
last
–
int
Informs the view that the rows from the
start
row to the
end
row inclusive have been removed from the given
parent
model item.
PySide2.QtWidgets.QTreeView.
setAllColumnsShowFocus
(
enable
)
¶
enable
–
bool
PySide2.QtWidgets.QTreeView.
setAnimated
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QTreeView.
setAutoExpandDelay
(
delay
)
¶
delay
–
int
另请参阅
PySide2.QtWidgets.QTreeView.
setColumnHidden
(
column
,
hide
)
¶
column
–
int
hide
–
bool
若
hide
为 true
column
被隐藏,否则
column
被展示。
PySide2.QtWidgets.QTreeView.
setColumnWidth
(
column
,
width
)
¶
column
–
int
width
–
int
设置宽度为给定
column
到
width
指定。
PySide2.QtWidgets.QTreeView.
setExpanded
(
index
,
expand
)
¶
index
–
QModelIndex
expand
–
bool
Sets the item referred to by
index
to either collapse or expanded, depending on the value of
expanded
.
PySide2.QtWidgets.QTreeView.
setExpandsOnDoubleClick
(
enable
)
¶
enable
–
bool
PySide2.QtWidgets.QTreeView.
setFirstColumnSpanned
(
row
,
parent
,
span
)
¶
row
–
int
parent
–
QModelIndex
span
–
bool
若
span
is true the item in the first column in the
row
采用给定
parent
is set to span all columns, otherwise all items on the
row
are shown.
PySide2.QtWidgets.QTreeView.
setHeader
(
header
)
¶
header
–
QHeaderView
Sets the header for the tree view, to the given
header
.
The view takes ownership over the given
header
and deletes it when a new header is set.
另请参阅
headerData()
PySide2.QtWidgets.QTreeView.
setHeaderHidden
(
hide
)
¶
hide
–
bool
另请参阅
PySide2.QtWidgets.QTreeView.
setIndentation
(
i
)
¶
i
–
int
另请参阅
PySide2.QtWidgets.QTreeView.
setItemsExpandable
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QTreeView.
setRootIsDecorated
(
show
)
¶
show
–
bool
另请参阅
PySide2.QtWidgets.QTreeView.
setRowHidden
(
row
,
parent
,
hide
)
¶
row
–
int
parent
–
QModelIndex
hide
–
bool
若
hide
为 true
row
采用给定
parent
被隐藏,否则
row
被展示。
PySide2.QtWidgets.QTreeView.
setSortingEnabled
(
enable
)
¶
enable
–
bool
另请参阅
PySide2.QtWidgets.QTreeView.
setTreePosition
(
logicalIndex
)
¶
logicalIndex
–
int
This specifies that the tree structure should be placed at logical index
index
. If set to -1 then the tree will always follow visual index 0.
PySide2.QtWidgets.QTreeView.
setUniformRowHeights
(
uniform
)
¶
uniform
–
bool
另请参阅
PySide2.QtWidgets.QTreeView.
setWordWrap
(
on
)
¶
on
–
bool
另请参阅
PySide2.QtWidgets.QTreeView.
showColumn
(
column
)
¶
column
–
int
展示给定
column
在树视图。
PySide2.QtWidgets.QTreeView.
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.QTreeView.
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.QTreeView.
treePosition
(
)
¶
int
Return the logical index the tree is set on. If the return value is -1 then the tree is placed on the visual index 0.
另请参阅
PySide2.QtWidgets.QTreeView.
uniformRowHeights
(
)
¶
bool
PySide2.QtWidgets.QTreeView.
wordWrap
(
)
¶
bool
另请参阅