PySide.QtGui.QHeaderView class provides a header row or header column for item views.
A PySide.QtGui.QHeaderView displays the headers used in item views such as the PySide.QtGui.QTableView and PySide.QtGui.QTreeView 类。它取代 Qt3 的 QHeader 类以前用于相同目的,但根据项视图类使用 Qt 的模型/视图体系结构。
PySide.QtGui.QHeaderView class is one of the 模型/视图类 且属于 Qt 的 模型/视图框架 .
头从模型获取每区间数据使用 QAbstractItemModel.headerData() function. You can set the data by using QAbstractItemModel.setHeaderData() .
每个头有 PySide.QtGui.QHeaderView.orientation() and a number of sections, given by the PySide.QtGui.QHeaderView.count() function. A section refers to a part of the header - either a row or a column, depending on the orientation.
区间可以被移动和重置尺寸使用 PySide.QtGui.QHeaderView.moveSection() and PySide.QtGui.QHeaderView.resizeSection() ; they can also be hidden and shown with PySide.QtGui.QHeaderView.hideSection() and PySide.QtGui.QHeaderView.showSection() .
Each section of a header is described by a section ID, specified by its section() , and can be located at a particular PySide.QtGui.QHeaderView.visualIndex() in the header. A section can have a sort indicator set with PySide.QtGui.QHeaderView.setSortIndicator() ; this indicates whether the items in the associated item view will be sorted in the order given by the section.
对于水平头,区间相当于模型列,对于垂直头,区间相当于模型行。
头位置可以固定,或使之可移动采用 PySide.QtGui.QHeaderView.setMovable() . It can be made clickable with PySide.QtGui.QHeaderView.setClickable() , and has resizing behavior in accordance with PySide.QtGui.QHeaderView.setResizeMode() .
注意
双击头调整区间尺寸仅适用于可见行。
头将发射 PySide.QtGui.QHeaderView.sectionMoved() if the user moves a section, PySide.QtGui.QHeaderView.sectionResized() if the user resizes a section, and PySide.QtGui.QHeaderView.sectionClicked() 及 PySide.QtGui.QHeaderView.sectionHandleDoubleClicked() in response to mouse clicks. A header will also emit PySide.QtGui.QHeaderView.sectionCountChanged() and PySide.QtGui.QHeaderView.sectionAutoResize() .
可以标识区间使用 PySide.QtGui.QHeaderView.logicalIndex() and PySide.QtGui.QHeaderView.logicalIndexAt() functions, or by its index position, using the PySide.QtGui.QHeaderView.visualIndex() and PySide.QtGui.QHeaderView.visualIndexAt() functions. The visual index will change if a section is moved, but the logical index will not change.
PySide.QtGui.QTableWidget and PySide.QtGui.QTableView 创建默认头。若希望头可见,可以使用 PySide.QtGui.QFrame.setVisible() .
并非所有 Qt.ItemDataRole s will have an effect on a PySide.QtGui.QHeaderView . If you need to draw other roles, you can subclass PySide.QtGui.QHeaderView and reimplement PySide.QtGui.QHeaderView.paintEvent() . PySide.QtGui.QHeaderView respects the following item data roles: TextAlignmentRole , DisplayRole , FontRole , DecorationRole , ForegroundRole ,和 BackgroundRole .
注意
每个头为每区间本身渲染数据,且不依赖委托。因此,调用头的 PySide.QtGui.QAbstractItemView.setItemDelegate() function will have no effect.
| 参数: |
|
|---|
重置尺寸模式指定头区间的行为。可以被设置在整个头视图或单个区间使用 PySide.QtGui.QHeaderView.setResizeMode() .
| 常量 | 描述 |
|---|---|
| QHeaderView.Interactive | 用户可以调整区间大小。也可以按编程方式调整区间大小使用 PySide.QtGui.QHeaderView.resizeSection() . The section size defaults to PySide.QtGui.QHeaderView.defaultSectionSize() 。(另请参阅 PySide.QtGui.QHeaderView.cascadingSectionResizes() .) |
| QHeaderView.Fixed | 用户无法调整区间大小。只可以按编程方式调整区间大小使用 PySide.QtGui.QHeaderView.resizeSection() . The section size defaults to PySide.QtGui.QHeaderView.defaultSectionSize() . |
| QHeaderView.Stretch | PySide.QtGui.QHeaderView 会自动调整区间大小以填充可用空间。尺寸无法被改变由用户或按编程方式。 |
| QHeaderView.ResizeToContents | PySide.QtGui.QHeaderView 将基于整列 (或整行) 内容自动把区间尺寸调整到最优大小。尺寸无法被改变由用户或按编程方式。(该值在 4.2 引入) |
以下值已过时:
| 常量 | 描述 |
|---|---|
| QHeaderView.Custom | 使用 Fixed 代替。 |
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds whether interactive resizing will be cascaded to the following sections once the section being resized by the user has reached its minimum size.
此特性只影响区间拥有 Interactive 作为其重置尺寸模式。
默认值为 false。
| 返回类型: | PySide.QtCore.int |
|---|
返回 Header 头的区间数。
| 返回类型: | PySide.QtCore.Qt.Alignment |
|---|
This property holds the default alignment of the text in each header section.
| 返回类型: | PySide.QtCore.int |
|---|
This property holds the default size of the header sections before resizing..
此特性只影响区间拥有 Interactive or Fixed 作为其重置尺寸模式。
| 参数: |
|
|---|
| 返回类型: | PySide.QtCore.int |
|---|
返回已隐藏的头区间数。
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
Hides the section specified by logicalIndex .
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds whether the sections containing selected items are highlighted.
默认情况下,此特性为 false。
| 参数: | option – PySide.QtGui.QStyleOptionHeader |
|---|
初始化 option 采用值来自此 PySide.QtGui.QHeaderView 。此方法对子类是有用的,当需要 PySide.QtGui.QStyleOptionHeader , but do not want to fill in all the information themselves.
| 参数: |
|
|---|
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the header is clickable; otherwise returns 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.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the header can be moved by the user; otherwise returns false.
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise returns false.
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds whether the sort indicator is shown.
默认情况下,此特性为 false。
| 返回类型: | PySide.QtCore.int |
|---|
返回沿 Header 头方向的长度。
另请参阅
PySide.QtGui.QHeaderView.sizeHint() PySide.QtGui.QHeaderView.setResizeMode() PySide.QtGui.QHeaderView.offset()
| 参数: | visualIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 or visualIndex >= QHeaderView.count() .
Note that the visualIndex is not affected by hidden sections.
| 参数: |
|
|---|---|
| 返回类型: |
PySide.QtCore.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.
| 参数: | position – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the section that covers the given position in the viewport.
| 参数: | pos – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the logical index of the section at the position given in pos . If the header is horizontal the x-coordinate will be used, otherwise the y-coordinate will be used to find the logical index.
| 返回类型: | PySide.QtCore.int |
|---|
This property holds the minimum size of the header sections..
最小区间尺寸是允许的最小区间尺寸。若最小区间尺寸被设为 -1, PySide.QtGui.QHeaderView 将使用最大的 global strut 或 font metrics 尺寸。
此特性被承兑由所有 resize modes .
| 参数: |
|
|---|
Moves the section at visual index from to occupy visual index to .
| 返回类型: | PySide.QtCore.int |
|---|
Returns the offset of the header: this is the header's left-most (or top-most for vertical headers) visible pixel.
| 返回类型: | PySide.QtCore.Qt.Orientation |
|---|
返回头的取向。
另请参阅
Qt.Orientation
| 参数: |
|
|---|
Paints the section specified by the given logicalIndex ,使用给定 painter and rect .
通常,不必调用此函数。
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtGui.QHeaderView.ResizeMode |
Returns the resize mode that applies to the section specified by the given logicalIndex .
| 参数: |
|
|---|
重置指定区间尺寸为 logicalIndex to size measured in pixels.
| 参数: | mode – PySide.QtGui.QHeaderView.ResizeMode |
|---|
调整区间大小根据其尺寸提示。通常,不必调用此函数。
| 参数: | state – PySide.QtCore.QByteArray |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Restores the state of this header view. This function returns true if the state was restored; otherwise returns false.
| 返回类型: | PySide.QtCore.QByteArray |
|---|
保存此头视图的当前状态。
要还原保存状态,把返回值传递给 PySide.QtGui.QHeaderView.restoreState() .
| 参数: |
|
|---|
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
| 参数: |
|
|---|
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
| 参数: |
|
|---|
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.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.
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
| 参数: |
|
|---|
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the width (or height for vertical headers) of the given logicalIndex .
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.QSize |
Returns the size of the contents of the section specified by the given logicalIndex .
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns a suitable size hint for the section specified by logicalIndex .
另请参阅
PySide.QtGui.QHeaderView.sizeHint() PySide.QtGui.QHeaderView.defaultSectionSize() PySide.QtGui.QHeaderView.minimumSectionSize() Qt.SizeHintRole
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the section viewport position of the given logicalIndex .
如果区间被隐藏,返回值不确定。
| 参数: |
|
|---|
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.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if sections in the header has been hidden; otherwise returns false;
| 参数: |
|
|---|
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.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if sections in the header has been moved; otherwise returns false;
| 参数: | enable – PySide.QtCore.bool |
|---|
This property holds whether interactive resizing will be cascaded to the following sections once the section being resized by the user has reached its minimum size.
此特性只影响区间拥有 Interactive 作为其重置尺寸模式。
默认值为 false。
| 参数: | clickable – PySide.QtCore.bool |
|---|
若 clickable 为 true,头将响应单击。
| 参数: | alignment – PySide.QtCore.Qt.Alignment |
|---|
This property holds the default alignment of the text in each header section.
| 参数: | size – PySide.QtCore.int |
|---|
This property holds the default size of the header sections before resizing..
此特性只影响区间拥有 Interactive or Fixed 作为其重置尺寸模式。
| 参数: | highlight – PySide.QtCore.bool |
|---|
This property holds whether the sections containing selected items are highlighted.
默认情况下,此特性为 false。
| 参数: | size – PySide.QtCore.int |
|---|
This property holds the minimum size of the header sections..
最小区间尺寸是允许的最小区间尺寸。若最小区间尺寸被设为 -1, PySide.QtGui.QHeaderView 将使用最大的 global strut 或 font metrics 尺寸。
此特性被承兑由所有 resize modes .
| 参数: | movable – PySide.QtCore.bool |
|---|
若 movable is true, the header may be moved by the user; otherwise it is fixed in place.
| 参数: | offset – PySide.QtCore.int |
|---|
把头的偏移设为 offset .
设置偏移以使最后区间可见。
| 参数: | visualIndex – PySide.QtCore.int |
|---|
Sets the offset to the start of the section at the given visualIndex .
| 参数: |
|
|---|
这是重载函数。
设置区间如何被约束指定通过 logicalIndex 在头中可以重置到那些描述大小通过给定 mode 。逻辑索引应该存在,当此函数被调用时。
注意
最后区间会忽略此设置若 PySide.QtGui.QHeaderView.stretchLastSection() 特性被设为 true。这是默认的对于水平头提供通过 PySide.QtGui.QTreeView .
| 参数: | mode – PySide.QtGui.QHeaderView.ResizeMode |
|---|
设置如何把头重置到哪些描述大小的约束通过给定 mode .
| 参数: |
|
|---|
若 hide 为 true 区间指定通过 logicalIndex 被隐藏;否则展示区间。
| 参数: |
|
|---|
| 参数: | show – PySide.QtCore.bool |
|---|
This property holds whether the sort indicator is shown.
默认情况下,此特性为 false。
| 参数: | stretch – PySide.QtCore.bool |
|---|
This property holds whether the last visible section in the header takes up all the available space.
默认值为 false。
注意
水平头提供由 PySide.QtGui.QTreeView 此特性配置被设为 true,确保视图不浪费为头赋值的任何空间。若此值被设为 true,此特性将覆盖头最后区间设置的重置尺寸模式。
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
显示指定区间通过 logicalIndex .
| 参数: |
|
|---|
| 返回类型: | PySide.QtCore.Qt.SortOrder |
|---|
Returns the order for the sort indicator. If no section has a sort indicator the return value of this function is undefined.
| 返回类型: | PySide.QtCore.int |
|---|
Returns the logical index of the section that has a sort indicator. By default this is section 0.
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds whether the last visible section in the header takes up all the available space.
默认值为 false。
注意
水平头提供由 PySide.QtGui.QTreeView 此特性配置被设为 true,确保视图不浪费为头赋值的任何空间。若此值被设为 true,此特性将覆盖头最后区间设置的重置尺寸模式。
| 返回类型: | PySide.QtCore.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.
| 参数: |
|
|---|
Swaps the section at visual index first with the section at visual index second .
| 参数: | logicalIndex – PySide.QtCore.int |
|---|
Updates the section specified by the given logicalIndex .
| 参数: | logicalIndex – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the visual index position of the section specified by the given logicalIndex , or -1 otherwise.
被隐藏区间仍具有有效视觉索引。
| 参数: | position – PySide.QtCore.int |
|---|---|
| 返回类型: | PySide.QtCore.int |
Returns the visual index of the section that covers the given position in the viewport.