QHeaderViewclass provides a header row or header column for item views. 更多 …
def
cascadingSectionResizes
()
def
count
()
def
defaultAlignment
()
def
defaultSectionSize
()
def
hiddenSectionCount
()
def
hideSection
(logicalIndex)
def
highlightSections
()
def
initStyleOption
(option)
def
initialize
()
def
initializeSections
()
def
initializeSections
(start, end)
def
isFirstSectionMovable
()
def
isSectionHidden
(logicalIndex)
def
isSortIndicatorShown
()
def
length
()
def
logicalIndex
(visualIndex)
def
logicalIndexAt
(pos)
def
logicalIndexAt
(position)
def
logicalIndexAt
(x, y)
def
maximumSectionSize
()
def
minimumSectionSize
()
def
moveSection
(from, to)
def
offset
()
def
orientation
()
def
resetDefaultSectionSize
()
def
resizeContentsPrecision
()
def
resizeSection
(logicalIndex, size)
def
resizeSections
(mode)
def
restoreState
(state)
def
saveState
()
def
sectionPosition
(logicalIndex)
def
sectionResizeMode
(logicalIndex)
def
sectionSize
(logicalIndex)
def
sectionSizeHint
(logicalIndex)
def
sectionViewportPosition
(logicalIndex)
def
sectionsClickable
()
def
sectionsHidden
()
def
sectionsMovable
()
def
sectionsMoved
()
def
setCascadingSectionResizes
(enable)
def
setDefaultAlignment
(alignment)
def
setDefaultSectionSize
(size)
def
setFirstSectionMovable
(movable)
def
setHighlightSections
(highlight)
def
setMaximumSectionSize
(size)
def
setMinimumSectionSize
(size)
def
setResizeContentsPrecision
(precision)
def
setSectionHidden
(logicalIndex, hide)
def
setSectionResizeMode
(logicalIndex, mode)
def
setSectionResizeMode
(mode)
def
setSectionsClickable
(clickable)
def
setSectionsMovable
(movable)
def
setSortIndicator
(logicalIndex, order)
def
setSortIndicatorShown
(show)
def
setStretchLastSection
(stretch)
def
showSection
(logicalIndex)
def
sortIndicatorOrder
()
def
sortIndicatorSection
()
def
stretchLastSection
()
def
stretchSectionCount
()
def
swapSections
(first, second)
def
visualIndex
(logicalIndex)
def
visualIndexAt
(position)
def
paintSection
(painter, rect, logicalIndex)
def
sectionSizeFromContents
(logicalIndex)
def
headerDataChanged
(orientation, logicalFirst, logicalLast)
def
resizeSections
()
def
sectionsAboutToBeRemoved
(parent, logicalFirst, logicalLast)
def
sectionsInserted
(parent, logicalFirst, logicalLast)
def
setOffset
(offset)
def
setOffsetToLastSection
()
def
setOffsetToSectionPosition
(visualIndex)
def
updateSection
(logicalIndex)
def
geometriesChanged
()
def
sectionClicked
(logicalIndex)
def
sectionCountChanged
(oldCount, newCount)
def
sectionDoubleClicked
(logicalIndex)
def
sectionEntered
(logicalIndex)
def
sectionHandleDoubleClicked
(logicalIndex)
def
sectionMoved
(logicalIndex, oldVisualIndex, newVisualIndex)
def
sectionPressed
(logicalIndex)
def
sectionResized
(logicalIndex, oldSize, newSize)
def
sortIndicatorChanged
(logicalIndex, order)
A
QHeaderViewdisplays the headers used in item views such as theQTableViewandQTreeViewclasses. It takes the place of Qt3’sQHeaderclass previously used for the same purpose, but uses the Qt’s model/view architecture for consistency with the item view classes.
QHeaderViewclass is one of the 模型/视图类 and is part of Qt’s 模型/视图框架 .头从模型获取每区间数据使用
headerData()function. You can set the data by usingsetHeaderData().每个头有
orientation()and a number of sections, given by thecount()function. A section refers to a part of the header - either a row or a column, depending on the orientation.区间可以被移动和重置尺寸使用
moveSection()andresizeSection(); they can also be hidden and shown withhideSection()andshowSection().头的每区间由区间 ID 描述,指定通过其 section(),且可以位于特定
visualIndex()in the header. A section can have a sort indicator set withsetSortIndicator(); this indicates whether the items in the associated item view will be sorted in the order given by the section.对于水平头,区间相当于模型列,对于垂直头,区间相当于模型行。
头位置可以固定,或使之可移动采用
setSectionsMovable(). It can be made clickable withsetSectionsClickable(), and has resizing behavior in accordance withsetSectionResizeMode().注意
双击头调整区间尺寸仅适用于可见行。
头将发射
sectionMoved()if the user moves a section,sectionResized()if the user resizes a section, andsectionClicked()及sectionHandleDoubleClicked()in response to mouse clicks. A header will also emitsectionCountChanged().可以标识区间使用
logicalIndex()andlogicalIndexAt()functions, or by its index position, using thevisualIndex()andvisualIndexAt()functions. The visual index will change if a section is moved, but the logical index will not change.
QTableWidgetandQTableView创建默认头。若希望头可见,可以使用setVisible().并非所有
ItemDataRoles will have an effect on aQHeaderView. If you need to draw other roles, you can subclassQHeaderViewand reimplementpaintEvent().QHeaderViewrespects the following item data roles, unless they are in conflict with the style (which can happen for styles that follow the desktop theme):
TextAlignmentRole,DisplayRole,FontRole,DecorationRole,ForegroundRole,和BackgroundRole.注意
Each header renders the data for each section itself, and does not rely on a delegate. As a result, calling a header’s
setItemDelegate()function will have no effect.
QHeaderView
(
orientation
[
,
parent=None
]
)
¶
- param parent
- param orientation
取向
创建新通用头采用给定
orientation
and
parent
.
PySide2.QtWidgets.QHeaderView.
ResizeMode
¶
重置尺寸模式指定头区间的行为。可以被设置在整个头视图或单个区间使用
setSectionResizeMode()
.
|
常量 |
描述 |
|---|---|
|
QHeaderView.Interactive |
用户可以调整区间大小。也可以按编程方式调整区间大小使用
|
|
QHeaderView.Fixed |
用户无法调整区间大小。只可以按编程方式调整区间大小使用
|
|
QHeaderView.Stretch |
|
|
QHeaderView.ResizeToContents |
|
以下值已过时:
|
常量 |
描述 |
|---|---|
|
QHeaderView.Custom |
使用 Fixed 代替。 |
PySide2.QtWidgets.QHeaderView.
cascadingSectionResizes
(
)
¶
bool
PySide2.QtWidgets.QHeaderView.
count
(
)
¶
int
返回 Header 头的区间数。
PySide2.QtWidgets.QHeaderView.
defaultAlignment
(
)
¶
Alignment
PySide2.QtWidgets.QHeaderView.
defaultSectionSize
(
)
¶
int
PySide2.QtWidgets.QHeaderView.
geometriesChanged
(
)
¶
PySide2.QtWidgets.QHeaderView.
headerDataChanged
(
orientation
,
logicalFirst
,
logicalLast
)
¶
orientation
–
取向
logicalFirst
–
int
logicalLast
–
int
更新改变头区间采用给定
orientation
,从
logicalFirst
to
logicalLast
包含在内。
int
返回已隐藏的头区间数。
PySide2.QtWidgets.QHeaderView.
hideSection
(
logicalIndex
)
¶
logicalIndex
–
int
Hides the section specified by
logicalIndex
.
PySide2.QtWidgets.QHeaderView.
highlightSections
(
)
¶
bool
PySide2.QtWidgets.QHeaderView.
initStyleOption
(
option
)
¶
option
–
QStyleOptionHeader
初始化
option
采用值来自此
QHeaderView
。此方法对子类是有用的,当需要
QStyleOptionHeader
, but do not want to fill in all the information themselves.
另请参阅
PySide2.QtWidgets.QHeaderView.
initialize
(
)
¶
PySide2.QtWidgets.QHeaderView.
initializeSections
(
)
¶
PySide2.QtWidgets.QHeaderView.
initializeSections
(
start
,
end
)
¶
start
–
int
end
–
int
PySide2.QtWidgets.QHeaderView.
isFirstSectionMovable
(
)
¶
bool
PySide2.QtWidgets.QHeaderView.
isSectionHidden
(
logicalIndex
)
¶
logicalIndex
–
int
bool
返回
true
if the section specified by
logicalIndex
is explicitly hidden from the user; otherwise returns
false
.
PySide2.QtWidgets.QHeaderView.
isSortIndicatorShown
(
)
¶
bool
PySide2.QtWidgets.QHeaderView.
length
(
)
¶
int
返回沿 Header 头方向的长度。
另请参阅
sizeHint()
setSectionResizeMode()
offset()
PySide2.QtWidgets.QHeaderView.
logicalIndex
(
visualIndex
)
¶
visualIndex
–
int
int
Returns the for the section at the given
visualIndex
position, or -1 if
visualIndex
< 0 or
visualIndex
>=
count()
.
注意:
visualIndex
is not affected by hidden sections.
PySide2.QtWidgets.QHeaderView.
logicalIndexAt
(
pos
)
¶
pos
–
QPoint
int
PySide2.QtWidgets.QHeaderView.
logicalIndexAt
(
position
)
¶
position
–
int
int
Returns the section that covers the given
position
in the viewport.
PySide2.QtWidgets.QHeaderView.
logicalIndexAt
(
x
,
y
)
¶
x
–
int
y
–
int
int
Returns the logical index of the section at the given coordinate. If the header is horizontal
x
will be used, otherwise
y
will be used to find the logical index.
PySide2.QtWidgets.QHeaderView.
maximumSectionSize
(
)
¶
int
PySide2.QtWidgets.QHeaderView.
minimumSectionSize
(
)
¶
int
PySide2.QtWidgets.QHeaderView.
moveSection
(
from
,
to
)
¶
from
–
int
to
–
int
Moves the section at visual index
from
to occupy visual index
to
.
另请参阅
PySide2.QtWidgets.QHeaderView.
offset
(
)
¶
int
Returns the offset of the header: this is the header’s left-most (or top-most for vertical headers) visible pixel.
另请参阅
PySide2.QtWidgets.QHeaderView.
orientation
(
)
¶
取向
返回头的取向。
另请参阅
取向
PySide2.QtWidgets.QHeaderView.
paintSection
(
painter
,
rect
,
logicalIndex
)
¶
painter
–
QPainter
rect
–
QRect
logicalIndex
–
int
Paints the section specified by the given
logicalIndex
,使用给定
painter
and
rect
.
通常,不必调用此函数。
PySide2.QtWidgets.QHeaderView.
resetDefaultSectionSize
(
)
¶
PySide2.QtWidgets.QHeaderView.
resizeContentsPrecision
(
)
¶
int
Returns how precise
QHeaderView
will calculate on
ResizeToContents
.
PySide2.QtWidgets.QHeaderView.
resizeSection
(
logicalIndex
,
size
)
¶
logicalIndex
–
int
size
–
int
重置指定区间尺寸为
logicalIndex
to
size
measured in pixels. The size parameter must be a value larger or equal to zero. A size equal to zero is however not recommended. In that situation
hideSection
should be used instead.
PySide2.QtWidgets.QHeaderView.
resizeSections
(
)
¶
调整区间大小根据其尺寸提示。通常,不必调用此函数。
PySide2.QtWidgets.QHeaderView.
resizeSections
(
mode
)
¶
mode
–
ResizeMode
Resizes the sections according to the given
mode
, ignoring the current resize mode.
另请参阅
PySide2.QtWidgets.QHeaderView.
restoreState
(
state
)
¶
state
–
QByteArray
bool
Restores the
state
of this header view. This function returns
true
if the state was restored; otherwise returns false.
另请参阅
PySide2.QtWidgets.QHeaderView.
saveState
(
)
¶
QByteArray
保存此头视图的当前状态。
要还原保存状态,把返回值传递给
restoreState()
.
另请参阅
PySide2.QtWidgets.QHeaderView.
sectionClicked
(
logicalIndex
)
¶
logicalIndex
–
int
PySide2.QtWidgets.QHeaderView.
sectionCountChanged
(
oldCount
,
newCount
)
¶
oldCount
–
int
newCount
–
int
PySide2.QtWidgets.QHeaderView.
sectionDoubleClicked
(
logicalIndex
)
¶
logicalIndex
–
int
PySide2.QtWidgets.QHeaderView.
sectionEntered
(
logicalIndex
)
¶
logicalIndex
–
int
PySide2.QtWidgets.QHeaderView.
sectionHandleDoubleClicked
(
logicalIndex
)
¶
logicalIndex
–
int
PySide2.QtWidgets.QHeaderView.
sectionMoved
(
logicalIndex
,
oldVisualIndex
,
newVisualIndex
)
¶
logicalIndex
–
int
oldVisualIndex
–
int
newVisualIndex
–
int
PySide2.QtWidgets.QHeaderView.
sectionPosition
(
logicalIndex
)
¶
logicalIndex
–
int
int
Returns the section position of the given
logicalIndex
, or -1 if the section is hidden. The position is measured in pixels from the first visible item’s top-left corner to the top-left corner of the item with
logicalIndex
. The measurement is along the x-axis for horizontal headers and along the y-axis for vertical headers.
PySide2.QtWidgets.QHeaderView.
sectionPressed
(
logicalIndex
)
¶
logicalIndex
–
int
PySide2.QtWidgets.QHeaderView.
sectionResizeMode
(
logicalIndex
)
¶
logicalIndex
–
int
Returns the resize mode that applies to the section specified by the given
logicalIndex
.
PySide2.QtWidgets.QHeaderView.
sectionResized
(
logicalIndex
,
oldSize
,
newSize
)
¶
logicalIndex
–
int
oldSize
–
int
newSize
–
int
PySide2.QtWidgets.QHeaderView.
sectionSize
(
logicalIndex
)
¶
logicalIndex
–
int
int
Returns the width (or height for vertical headers) of the given
logicalIndex
.
PySide2.QtWidgets.QHeaderView.
sectionSizeFromContents
(
logicalIndex
)
¶
logicalIndex
–
int
QSize
Returns the size of the contents of the section specified by the given
logicalIndex
.
另请参阅
PySide2.QtWidgets.QHeaderView.
sectionSizeHint
(
logicalIndex
)
¶
logicalIndex
–
int
int
Returns a suitable size hint for the section specified by
logicalIndex
.
SizeHintRole
另请参阅
sizeHint()
defaultSectionSize()
minimumSectionSize()
maximumSectionSize()
PySide2.QtWidgets.QHeaderView.
sectionViewportPosition
(
logicalIndex
)
¶
logicalIndex
–
int
int
Returns the section viewport position of the given
logicalIndex
.
如果区间被隐藏,返回值不确定。
PySide2.QtWidgets.QHeaderView.
sectionsAboutToBeRemoved
(
parent
,
logicalFirst
,
logicalLast
)
¶
parent
–
QModelIndex
logicalFirst
–
int
logicalLast
–
int
This slot is called when sections are removed from the
parent
.
logicalFirst
and
logicalLast
signify where the sections were removed.
If only one section is removed,
logicalFirst
and
logicalLast
will be the same.
PySide2.QtWidgets.QHeaderView.
sectionsClickable
(
)
¶
bool
返回
true
若 Header 头是可点击的;否则返回
false
. A clickable header could be set up to allow the user to change the representation of the data in the view related to the header.
PySide2.QtWidgets.QHeaderView.
sectionsHidden
(
)
¶
bool
返回
true
若 Header 头区间被隐藏;否则返回 false;
另请参阅
PySide2.QtWidgets.QHeaderView.
sectionsInserted
(
parent
,
logicalFirst
,
logicalLast
)
¶
parent
–
QModelIndex
logicalFirst
–
int
logicalLast
–
int
This slot is called when sections are inserted into the
parent
.
logicalFirst
and
logicalLast
indices signify where the new sections were inserted.
If only one section is inserted,
logicalFirst
and
logicalLast
will be the same.
PySide2.QtWidgets.QHeaderView.
sectionsMovable
(
)
¶
bool
返回
true
若 Header 头可以被用户移动;否则返回 false。
By default, sections are movable in
QTreeView
(except for the first one), and not movable in
QTableView
.
另请参阅
PySide2.QtWidgets.QHeaderView.
sectionsMoved
(
)
¶
bool
返回
true
若 Header 头区间已被移动;否则返回 false;
另请参阅
PySide2.QtWidgets.QHeaderView.
setCascadingSectionResizes
(
enable
)
¶
enable
–
bool
PySide2.QtWidgets.QHeaderView.
setDefaultAlignment
(
alignment
)
¶
alignment
–
Alignment
另请参阅
PySide2.QtWidgets.QHeaderView.
setDefaultSectionSize
(
size
)
¶
size
–
int
另请参阅
PySide2.QtWidgets.QHeaderView.
setFirstSectionMovable
(
movable
)
¶
movable
–
bool
PySide2.QtWidgets.QHeaderView.
setHighlightSections
(
highlight
)
¶
highlight
–
bool
另请参阅
PySide2.QtWidgets.QHeaderView.
setMaximumSectionSize
(
size
)
¶
size
–
int
另请参阅
PySide2.QtWidgets.QHeaderView.
setMinimumSectionSize
(
size
)
¶
size
–
int
另请参阅
PySide2.QtWidgets.QHeaderView.
setOffset
(
offset
)
¶
offset
–
int
Sets the header’s offset to
offset
.
PySide2.QtWidgets.QHeaderView.
setOffsetToLastSection
(
)
¶
设置偏移以使最后区间可见。
PySide2.QtWidgets.QHeaderView.
setOffsetToSectionPosition
(
visualIndex
)
¶
visualIndex
–
int
Sets the offset to the start of the section at the given
visualSectionNumber
.
visualSectionNumber
is the actual visible section when hiddenSections are not considered. That is not always the same as
visualIndex()
.
PySide2.QtWidgets.QHeaderView.
setResizeContentsPrecision
(
precision
)
¶
precision
–
int
Sets how precise
QHeaderView
should calculate the size when
ResizeToContents
is used. A low value will provide a less accurate but fast auto resize while a higher value will provide a more accurate resize that however can be slow.
The number
precision
specifies how many sections that should be consider when calculating the preferred size.
The default value is 1000 meaning that a horizontal column with auto-resize will look at maximum 1000 rows on calculating when doing an auto resize.
Special value 0 means that it will look at only the visible area. Special value -1 will imply looking at all elements.
This value is used in
sizeHintForColumn()
,
sizeHintForRow()
and
sizeHintForColumn()
. Reimplementing these functions can make this function not having an effect.
另请参阅
resizeContentsPrecision()
setSectionResizeMode()
resizeSections()
sizeHintForColumn()
sizeHintForRow()
sizeHintForColumn()
PySide2.QtWidgets.QHeaderView.
setSectionHidden
(
logicalIndex
,
hide
)
¶
logicalIndex
–
int
hide
–
bool
若
hide
为 true 区间指定通过
logicalIndex
被隐藏;否则展示区间。
PySide2.QtWidgets.QHeaderView.
setSectionResizeMode
(
mode
)
¶
mode
–
ResizeMode
设置如何把头重置到哪些描述大小的约束通过给定
mode
.
PySide2.QtWidgets.QHeaderView.
setSectionResizeMode
(
logicalIndex
,
mode
)
¶
logicalIndex
–
int
mode
–
ResizeMode
设置区间如何被约束指定通过
logicalIndex
在头中可以重置到那些描述大小通过给定
mode
。逻辑索引应该存在,当此函数被调用时。
注意
最后区间会忽略此设置若
stretchLastSection
特性被设为 true。这是默认的对于水平头提供通过
QTreeView
.
PySide2.QtWidgets.QHeaderView.
setSectionsClickable
(
clickable
)
¶
clickable
–
bool
若
clickable
为 true,头将响应单击。
PySide2.QtWidgets.QHeaderView.
setSectionsMovable
(
movable
)
¶
movable
–
bool
若
movable
为 true,用户可以移动 Header 头区间;否则,它们被固定在原地。
当组合使用同
QTreeView
,第一列是不可移动的 (因为它包含树结构) 默认情况下。可以使之可移动采用
setFirstSectionMovable
(true)。
PySide2.QtWidgets.QHeaderView.
setSortIndicator
(
logicalIndex
,
order
)
¶
logicalIndex
–
int
order
–
SortOrder
Sets the sort indicator for the section specified by the given
logicalIndex
in the direction specified by
order
, and removes the sort indicator from any other section that was showing it.
logicalIndex
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.
PySide2.QtWidgets.QHeaderView.
setSortIndicatorShown
(
show
)
¶
show
–
bool
PySide2.QtWidgets.QHeaderView.
setStretchLastSection
(
stretch
)
¶
stretch
–
bool
另请参阅
PySide2.QtWidgets.QHeaderView.
showSection
(
logicalIndex
)
¶
logicalIndex
–
int
显示指定区间通过
logicalIndex
.
PySide2.QtWidgets.QHeaderView.
sortIndicatorChanged
(
logicalIndex
,
order
)
¶
logicalIndex
–
int
order
–
SortOrder
PySide2.QtWidgets.QHeaderView.
sortIndicatorOrder
(
)
¶
SortOrder
Returns the order for the sort indicator. If no section has a sort indicator the return value of this function is undefined.
PySide2.QtWidgets.QHeaderView.
sortIndicatorSection
(
)
¶
int
Returns the logical index of the section that has a sort indicator. By default this is section 0.
PySide2.QtWidgets.QHeaderView.
stretchLastSection
(
)
¶
bool
PySide2.QtWidgets.QHeaderView.
stretchSectionCount
(
)
¶
int
Returns the number of sections that are set to resize mode stretch. In views, this can be used to see if the headerview needs to resize the sections when the view’s geometry changes.
另请参阅
PySide2.QtWidgets.QHeaderView.
swapSections
(
first
,
second
)
¶
first
–
int
second
–
int
Swaps the section at visual index
first
with the section at visual index
second
.
另请参阅
PySide2.QtWidgets.QHeaderView.
updateSection
(
logicalIndex
)
¶
logicalIndex
–
int
Updates the section specified by the given
logicalIndex
.
PySide2.QtWidgets.QHeaderView.
visualIndex
(
logicalIndex
)
¶
logicalIndex
–
int
int
Returns the visual index position of the section specified by the given
logicalIndex
, or -1 otherwise.
被隐藏区间仍具有有效视觉索引。
另请参阅
PySide2.QtWidgets.QHeaderView.
visualIndexAt
(
position
)
¶
position
–
int
int
Returns the visual index of the section that covers the given
position
in the viewport.
另请参阅