内容表

上一话题

QHBoxLayout

下一话题

QInputDialog

QHeaderView

QHeaderView class provides a header row or header column for item views. 更多

Inheritance diagram of PySide2.QtWidgets.QHeaderView

概要

函数

虚函数

信号

详细描述

A QHeaderView displays the headers used in item views such as the QTableView and QTreeView classes. It takes the place of Qt3’s QHeader class previously used for the same purpose, but uses the Qt’s model/view architecture for consistency with the item view classes.

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

头从模型获取每区间数据使用 headerData() function. You can set the data by using setHeaderData() .

每个头有 orientation() and a number of sections, given by the count() function. A section refers to a part of the header - either a row or a column, depending on the orientation.

区间可以被移动和重置尺寸使用 moveSection() and resizeSection() ; they can also be hidden and shown with hideSection() and showSection() .

头的每区间由区间 ID 描述,指定通过其 section(),且可以位于特定 visualIndex() in the header. A section can have a sort indicator set with setSortIndicator() ; this indicates whether the items in the associated item view will be sorted in the order given by the section.

对于水平头,区间相当于模型列,对于垂直头,区间相当于模型行。

移动 Header 头区间

头位置可以固定,或使之可移动采用 setSectionsMovable() . It can be made clickable with setSectionsClickable() , and has resizing behavior in accordance with setSectionResizeMode() .

注意

双击头调整区间尺寸仅适用于可见行。

头将发射 sectionMoved() if the user moves a section, sectionResized() if the user resizes a section, and sectionClicked() sectionHandleDoubleClicked() in response to mouse clicks. A header will also emit sectionCountChanged() .

可以标识区间使用 logicalIndex() and logicalIndexAt() functions, or by its index position, using the visualIndex() and visualIndexAt() functions. The visual index will change if a section is moved, but the logical index will not change.

外观

QTableWidget and QTableView 创建默认头。若希望头可见,可以使用 setVisible() .

并非所有 ItemDataRole s will have an effect on a QHeaderView . If you need to draw other roles, you can subclass QHeaderView and reimplement paintEvent() . QHeaderView respects 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.

class QHeaderView ( orientation [ , parent=None ] )
param parent

QWidget

param orientation

取向

创建新通用头采用给定 orientation and parent .

PySide2.QtWidgets.QHeaderView. ResizeMode

重置尺寸模式指定头区间的行为。可以被设置在整个头视图或单个区间使用 setSectionResizeMode() .

常量

描述

QHeaderView.Interactive

用户可以调整区间大小。也可以按编程方式调整区间大小使用 resizeSection() . The section size defaults to defaultSectionSize 。(另请参阅 cascadingSectionResizes .)

QHeaderView.Fixed

用户无法调整区间大小。只可以按编程方式调整区间大小使用 resizeSection() . The section size defaults to defaultSectionSize .

QHeaderView.Stretch

QHeaderView 会自动调整区间大小以填充可用空间。尺寸无法被改变由用户或按编程方式。

QHeaderView.ResizeToContents

QHeaderView 将基于整列 (或整行) 内容自动把区间尺寸调整到最优大小。尺寸无法被改变由用户或按编程方式。(该值在 4.2 引入)

以下值已过时:

常量

描述

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 包含在内。

PySide2.QtWidgets.QHeaderView. hiddenSectionCount ( )
返回类型

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.

另请参阅

initFrom()

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 .

另请参阅

sectionsMoved()

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.

另请参阅

setOffset()

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.

另请参阅

sectionResized()

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.

另请参阅

saveState()

PySide2.QtWidgets.QHeaderView. saveState ( )
返回类型

QByteArray

保存此头视图的当前状态。

要还原保存状态,把返回值传递给 restoreState() .

另请参阅

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

返回类型

ResizeMode

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

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;

另请参阅

moveSection()

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 在头中可以重置到那些描述大小通过给定 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 .

另请参阅

moveSection()

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.

被隐藏区间仍具有有效视觉索引。

另请参阅

logicalIndex()

PySide2.QtWidgets.QHeaderView. visualIndexAt ( position )
参数

position int

返回类型

int

Returns the visual index of the section that covers the given position in the viewport.

另请参阅

logicalIndexAt()