The QHeaderView class provides a header row or header column for item views. 更多...
继承 QAbstractItemView .
The QHeaderView class provides a header row or header column for item views.
A QHeaderView displays the headers used in item views such as the QTableView and QTreeView 类。它取代 Qt3 的 QHeader class previously used for the same purpose, but uses the Qt's model/view architecture for consistency with the item view classes.
QHeaderView 类为 模型/视图类 且属于 Qt 的 模型/视图框架 .
The header gets the data for each section from the model using the QAbstractItemModel.headerData () function. You can set the data by using QAbstractItemModel.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 () 和 resizeSection (); they can also be hidden and shown with hideSection () 和 showSection ().
Each section of a header is described by a section ID, specified by its section(), and can be located at a particular 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.
For a horizontal header the section is equivalent to a column in the model, and for a vertical header the section is equivalent to a row in the model.
头位置可以固定,或使之可移动采用 setMovable (). It can be made clickable with setClickable (), and has resizing behavior in accordance with setResizeMode ().
注意: Double-clicking on a header to resize a section only applies for visible rows.
头将发射 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 () and sectionAutoResize ().
可以标识区间使用 logicalIndex () 和 logicalIndexAt () functions, or by its index position, using the visualIndex () 和 visualIndexAt () functions. The visual index will change if a section is moved, but the logical index will not change.
QTableWidget and QTableView create default headers. If you want the headers to be visible, you can use 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: 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.
The resize mode specifies the behavior of the header sections. It can be set on the entire header view or on individual sections 使用 setResizeMode ().
| 常量 | 值 | 描述 |
|---|---|---|
| QHeaderView.Interactive | 0 | The user can resize the section. The section can also be resized programmatically using resizeSection (). The section size defaults to defaultSectionSize . (See also cascadingSectionResizes .) |
| QHeaderView.Fixed | 2 | The user cannot resize the section. The section can only be resized programmatically using resizeSection (). The section size defaults to defaultSectionSize . |
| QHeaderView.Stretch | 1 | QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically. |
| QHeaderView.ResizeToContents | 3 | QHeaderView will automatically resize the section to its optimal size based on the contents of the entire column or row. The size cannot be changed by the user or programmatically. (This value was introduced in 4.2) |
以下值已过时:
| 常量 | 值 | 描述 |
|---|---|---|
| QHeaderView.Custom | Fixed | 使用 Fixed 代替。 |
另请参阅 setResizeMode (), stretchLastSection , and minimumSectionSize .
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
创建新通用头采用给定 orientation and parent .
返回 Header 头的区间数。
另请参阅 sectionCountChanged () and length ().
重实现自 QAbstractItemView.currentChanged ().
重实现自 QObject.event ().
This method is also a Qt slot with the C++ signature void headerDataChanged(Qt::Orientation,int,int) .
更新改变头区间采用给定 orientation ,从 logicalFirst to logicalLast 包含在内。
Returns the number of sections in the header that has been hidden.
该函数在 Qt 4.1 引入。
另请参阅 setSectionHidden () 和 isSectionHidden ().
Hides the section specified by logicalIndex .
另请参阅 showSection (), isSectionHidden (), hiddenSectionCount (),和 setSectionHidden ().
重实现自 QAbstractItemView.horizontalOffset ().
Returns the horizontal offset of the header. This is 0 for vertical headers.
另请参阅 offset ().
初始化 option 采用值来自此 QHeaderView . This method is useful for subclasses when they need a QStyleOptionHeader , but do not want to fill in all the information themselves.
另请参阅 QStyleOption.initFrom ().
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.
另请参阅 setClickable ().
Returns true if the header can be moved by the user; otherwise returns false.
另请参阅 setMovable ().
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise returns false.
另请参阅 hideSection (), showSection (), setSectionHidden (),和 hiddenSectionCount ().
返回沿 Header 头方向的长度。
另请参阅 sizeHint (), setResizeMode (),和 offset ().
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.
另请参阅 visualIndex () 和 sectionPosition ().
Returns the section that covers the given position 在 viewport.
另请参阅 visualIndexAt () 和 isSectionHidden ().
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.
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.
另请参阅 sectionPosition ().
重实现自 QWidget.mouseDoubleClickEvent ().
重实现自 QWidget.mouseMoveEvent ().
重实现自 QWidget.mousePressEvent ().
重实现自 QWidget.mouseReleaseEvent ().
Moves the section at visual index from to occupy visual index to .
另请参阅 sectionsMoved ().
Returns the offset of the header: this is the header's left-most (or top-most for vertical headers) visible pixel.
另请参阅 setOffset ().
返回头的取向。
另请参阅 Qt.Orientation .
重实现自 QWidget.paintEvent ().
Paints the section specified by the given logicalIndex , using the given painter and rect .
通常,不必调用此函数。
重实现自 QAbstractItemView.reset ().
Returns the resize mode that applies to the section specified by the given logicalIndex .
另请参阅 setResizeMode ().
重置指定区间尺寸为 logicalIndex to size measured in pixels.
另请参阅 sectionResized (), resizeMode (),和 sectionSize ().
This method is also a Qt slot with the C++ signature void resizeSections() .
Resizes the sections according to the given mode , ignoring the current resize mode.
另请参阅 resizeMode () 和 sectionResized ().
Resizes the sections according to their size hints. Normally, you do not have to call this function.
Restores the state of this header view. This function 返回 true if the state was restored; otherwise returns false.
该函数在 Qt 4.3 引入。
另请参阅 saveState ().
保存此头视图的当前状态。
要还原保存状态,把返回值传递给 restoreState ().
该函数在 Qt 4.3 引入。
另请参阅 restoreState ().
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.
另请参阅 sectionViewportPosition ().
This method is also a Qt slot with the C++ signature void sectionsAboutToBeRemoved(const QModelIndex&,int,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.
Returns true if sections in the header has been hidden; otherwise returns false;
该函数在 Qt 4.1 引入。
另请参阅 setSectionHidden ().
This method is also a Qt slot with the C++ signature void sectionsInserted(const QModelIndex&,int,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.
Returns the width (or height for vertical headers) of the given logicalIndex .
另请参阅 length (), setResizeMode (),和 defaultSectionSize ().
Returns the size of the contents of the section specified by the given logicalIndex .
另请参阅 defaultSectionSize ().
Returns a suitable size hint for the section specified by logicalIndex .
另请参阅 sizeHint (), defaultSectionSize (), minimumSectionSize (), and Qt.SizeHintRole .
Returns true if sections in the header has been moved; otherwise returns false;
另请参阅 moveSection ().
Returns the section viewport position of the given logicalIndex .
如果区间被隐藏,返回值不确定。
另请参阅 sectionPosition () 和 isSectionHidden ().
若 clickable is true, the header will respond to single clicks.
另请参阅 isClickable (), sectionClicked (), sectionPressed (),和 setSortIndicatorShown ().
重实现自 QAbstractItemView.setModel ().
若 movable is true, the header may be moved by the user; otherwise it is fixed in place.
另请参阅 isMovable () 和 sectionMoved ().
This method is also a Qt slot with the C++ signature void setOffset(int) .
把头的偏移设为 offset .
This method is also a Qt slot with the C++ signature void setOffsetToLastSection() .
设置偏移以使最后区间可见。
该函数在 Qt 4.2 引入。
另请参阅 setOffset (), sectionPosition (),和 setOffsetToSectionPosition ().
This method is also a Qt slot with the C++ signature void setOffsetToSectionPosition(int) .
Sets the offset to the start of the section at the given visualIndex .
该函数在 Qt 4.2 引入。
另请参阅 setOffset () 和 sectionPosition ().
Sets the constraints on how the header can be resized to those described by the given mode .
另请参阅 resizeMode (), length (), sectionResized (),和 sectionAutoResize ().
这是重载函数。
设置区间如何被约束指定通过 logicalIndex in the header can be resized to those described by the given mode . The logical index should exist at the time this function is called.
注意: This setting will be ignored for the last section 若 stretchLastSection property is set to true. This is the default for the horizontal headers provided by QTreeView .
另请参阅 setStretchLastSection ().
若 hide 为 true 区间指定通过 logicalIndex 被隐藏;否则展示区间。
另请参阅 isSectionHidden () 和 hiddenSectionCount ().
重实现自 QAbstractItemView.setSelection ().
Selects the items in the given rect according to the specified flags .
基类实现什么都不做。
Sets the sort indicator for the section specified by the given logicalIndex in the direction specified by order ,和 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.
另请参阅 sortIndicatorSection () and sortIndicatorOrder ().
显示指定区间通过 logicalIndex .
另请参阅 hideSection (), isSectionHidden (), hiddenSectionCount (),和 setSectionHidden ().
重实现自 QWidget.sizeHint ().
返回此 Header 头的适合尺寸提示。
另请参阅 sectionSizeHint ().
Returns the order for the sort indicator. If no section has a sort indicator the return value of this function is undefined.
另请参阅 setSortIndicator () 和 sortIndicatorSection ().
Returns the logical index of the section that has a sort indicator. By default this is section 0.
另请参阅 setSortIndicator (), sortIndicatorOrder (), and setSortIndicatorShown ().
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.
该函数在 Qt 4.1 引入。
另请参阅 stretchLastSection and resizeMode ().
Swaps the section at visual index first with the section at visual index second .
该函数在 Qt 4.2 引入。
另请参阅 moveSection ().
This method is also a Qt slot with the C++ signature void updateSection(int) .
重实现自 QAbstractItemView.verticalOffset ().
Returns the vertical offset of the header. This is 0 for horizontal headers.
另请参阅 offset ().
重实现自 QAbstractScrollArea.viewportEvent ().
Returns the visual index position of the section specified by the given logicalIndex , or -1 otherwise.
被隐藏区间仍具有有效视觉索引。
另请参阅 logicalIndex ().
Returns the visual index of the section that covers the given position in the viewport.
另请参阅 logicalIndexAt ().
This is the default overload of this signal.
This signal is emitted when the header's geometries have 改变。
该函数在 Qt 4.2 引入。
This is the default overload of this signal.
This signal is emitted when a section is automatically resized. The section's logical index is specified by logicalIndex , and the resize mode by mode .
另请参阅 setResizeMode () 和 stretchLastSection ().
This is the default overload of this signal.
This signal is emitted when a section is clicked. The section's logical index is specified by logicalIndex .
Note that the sectionPressed signal will also be emitted.
另请参阅 setClickable () 和 sectionPressed ().
This is the default overload of this signal.
This signal is emitted when the number of sections changes, i.e., when sections are added or deleted. The original count is 指定通过 oldCount , and the new count by newCount .
另请参阅 count (), length (),和 headerDataChanged ().
This is the default overload of this signal.
This signal is emitted when a section is double-clicked. The section's logical index is specified by logicalIndex .
另请参阅 setClickable ().
This is the default overload of this signal.
This signal is emitted when the cursor moves over the section and the left mouse button is pressed. The section's logical index is specified by logicalIndex .
该函数在 Qt 4.3 引入。
另请参阅 setClickable () 和 sectionPressed ().
This is the default overload of this signal.
This signal is emitted when a section is double-clicked. The section's logical index is specified by logicalIndex .
另请参阅 setClickable ().
This is the default overload of this signal.
This signal is emitted when a section is moved. The section's logical index is specified by logicalIndex , the old index by oldVisualIndex , and the new index position by newVisualIndex .
另请参阅 moveSection ().
This is the default overload of this signal.
This signal is emitted when a section is pressed. The section's logical index is specified by logicalIndex .
另请参阅 setClickable ().
This is the default overload of this signal.
This signal is emitted when a section is resized. The section's logical number is specified by logicalIndex , the old size by oldSize , and the new size by newSize .
另请参阅 resizeSection ().
This is the default overload of this signal.
This signal is emitted when the section containing the sort indicator or the order indicated is changed. The section's logical index is specified by logicalIndex and the sort order is 指定通过 order .
该函数在 Qt 4.3 引入。
另请参阅 setSortIndicator ().