QHeaderView 类为项视图提供 Header 头部行 (或 Header 头部列)。 更多...
头: | #include <QHeaderView> |
CMake: |
find_package(Qt6 COMPONENTS Widgets REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
继承: | QAbstractItemView |
enum | ResizeMode { Interactive, Fixed, Stretch, ResizeToContents, Custom } |
|
|
QHeaderView (Qt::Orientation orientation , QWidget * parent = nullptr) | |
virtual | ~QHeaderView () |
bool | cascadingSectionResizes () const |
int | count () const |
Qt::Alignment | defaultAlignment () const |
int | defaultSectionSize () const |
int | hiddenSectionCount () const |
void | hideSection (int logicalIndex ) |
bool | highlightSections () const |
bool | isFirstSectionMovable () const |
bool | isSectionHidden (int logicalIndex ) const |
bool | isSortIndicatorClearable () const |
bool | isSortIndicatorShown () const |
int | length () const |
int | logicalIndex (int visualIndex ) const |
int | logicalIndexAt (int position ) const |
int | logicalIndexAt (int x , int y ) const |
int | logicalIndexAt (const QPoint & pos ) const |
int | maximumSectionSize () const |
int | minimumSectionSize () const |
void | moveSection (int from , int to ) |
int | offset () const |
Qt::Orientation | orientation () const |
void | resetDefaultSectionSize () |
int | resizeContentsPrecision () const |
void | resizeSection (int logicalIndex , int size ) |
void | resizeSections (QHeaderView::ResizeMode mode ) |
bool | restoreState (const QByteArray & state ) |
QByteArray | saveState () const |
int | sectionPosition (int logicalIndex ) const |
QHeaderView::ResizeMode | sectionResizeMode (int logicalIndex ) const |
int | sectionSize (int logicalIndex ) const |
int | sectionSizeHint (int logicalIndex ) const |
int | sectionViewportPosition (int logicalIndex ) const |
bool | sectionsClickable () const |
bool | sectionsHidden () const |
bool | sectionsMovable () const |
bool | sectionsMoved () const |
void | setCascadingSectionResizes (bool enable ) |
void | setDefaultAlignment (Qt::Alignment alignment ) |
void | setDefaultSectionSize (int size ) |
void | setFirstSectionMovable (bool movable ) |
void | setHighlightSections (bool highlight ) |
void | setMaximumSectionSize (int size ) |
void | setMinimumSectionSize (int size ) |
void | setResizeContentsPrecision (int precision ) |
void | setSectionHidden (int logicalIndex , bool hide ) |
void | setSectionResizeMode (QHeaderView::ResizeMode mode ) |
void | setSectionResizeMode (int logicalIndex , QHeaderView::ResizeMode mode ) |
void | setSectionsClickable (bool clickable ) |
void | setSectionsMovable (bool movable ) |
void | setSortIndicator (int logicalIndex , Qt::SortOrder order ) |
void | setSortIndicatorClearable (bool clearable ) |
void | setSortIndicatorShown (bool show ) |
void | setStretchLastSection (bool stretch ) |
void | showSection (int logicalIndex ) |
Qt::SortOrder | sortIndicatorOrder () const |
int | sortIndicatorSection () const |
bool | stretchLastSection () const |
int | stretchSectionCount () const |
void | swapSections (int first , int second ) |
int | visualIndex (int logicalIndex ) const |
int | visualIndexAt (int position ) const |
virtual void | reset () override |
virtual void | setModel (QAbstractItemModel * model ) override |
virtual void | setVisible (bool v ) override |
virtual QSize | sizeHint () const override |
void | headerDataChanged (Qt::Orientation orientation , int logicalFirst , int logicalLast ) |
void | setOffset (int offset ) |
void | setOffsetToLastSection () |
void | setOffsetToSectionPosition (int visualSectionNumber ) |
void | geometriesChanged () |
void | sectionClicked (int logicalIndex ) |
void | sectionCountChanged (int oldCount , int newCount ) |
void | sectionDoubleClicked (int logicalIndex ) |
void | sectionEntered (int logicalIndex ) |
void | sectionHandleDoubleClicked (int logicalIndex ) |
void | sectionMoved (int logicalIndex , int oldVisualIndex , int newVisualIndex ) |
void | sectionPressed (int logicalIndex ) |
void | sectionResized (int logicalIndex , int oldSize , int newSize ) |
void | sortIndicatorChanged (int logicalIndex , Qt::SortOrder order ) |
void | sortIndicatorClearableChanged (bool clearable ) |
virtual void | initStyleOption (QStyleOptionHeader * option ) const |
virtual void | initStyleOptionForIndex (QStyleOptionHeader * option , int logicalIndex ) const |
virtual void | paintSection (QPainter * painter , const QRect & rect , int logicalIndex ) const |
virtual QSize | sectionSizeFromContents (int logicalIndex ) const |
virtual void | currentChanged (const QModelIndex & current , const QModelIndex & old ) override |
virtual bool | event (QEvent * e ) override |
virtual int | horizontalOffset () const override |
virtual void | mouseDoubleClickEvent (QMouseEvent * e ) override |
virtual void | mouseMoveEvent (QMouseEvent * e ) override |
virtual void | mousePressEvent (QMouseEvent * e ) override |
virtual void | mouseReleaseEvent (QMouseEvent * e ) override |
virtual void | paintEvent (QPaintEvent * e ) override |
virtual void | setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags flags ) override |
virtual int | verticalOffset () const override |
virtual bool | viewportEvent (QEvent * e ) override |
void | resizeSections () |
void | sectionsAboutToBeRemoved (const QModelIndex & parent , int logicalFirst , int logicalLast ) |
void | sectionsInserted (const QModelIndex & parent , int logicalFirst , int logicalLast ) |
QHeaderView 显示用于项视图的 Header 头部,譬如
QTableView
and
QTreeView
类。它取代 Qt3 的
QHeader
类以前用于相同目的,但根据项视图类使用 Qt 的模型/视图体系结构。
QHeaderView 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .
头从模型获取每区间数据使用 QAbstractItemModel::headerData () 函数。可以设置数据通过使用 QAbstractItemModel::setHeaderData ().
每个头有 orientation () 和许多区间,给定通过 count () 函数。区间引用头的一部分 - 行或列取决于取向。
区间可以被移动和重置尺寸使用 moveSection () 和 resizeSection ();它们还可以被隐藏和展示采用 hideSection () 和 showSection ().
头的每区间由区间 ID 描述,指定通过其 section(),且可以位于特定 visualIndex () 在头中。区间可以有排序指示器设置采用 setSortIndicator ();这指示关联项视图中的项是否将按区间给出的次序进行排序。
对于水平头,区间相当于模型列,对于垂直头,区间相当于模型行。
头位置可以固定,或使之可移动采用 setSectionsMovable ()。可以使之可点击采用 setSectionsClickable (),和拥有重置大小行为根据 setSectionResizeMode ().
注意: 双击头调整区间尺寸仅适用于可见行。
头将发射 sectionMoved () 若用户移动区间, sectionResized () 若用户调整区间尺寸,和 sectionClicked () 及 sectionHandleDoubleClicked () 响应鼠标点击。头还会发射 sectionCountChanged ().
可以标识区间使用 logicalIndex () 和 logicalIndexAt () 函数,或通过其索引位置,使用 visualIndex () 和 visualIndexAt () 函数。视觉索引会改变若区间被移动,但逻辑索引不会改变。
QTableWidget and QTableView 创建默认 Header 头部。若希望 Header 头部可见,可以使用 setVisible() .
并非所有 ItemDataRole 会对 QHeaderView 有影响。若需要绘制其它角色,可以子类化 QHeaderView 并重实现 paintEvent() 。QHeaderView 遵守以下项数据角色,除非它们与样式冲突 (遵循桌面主题的样式会发生):
TextAlignmentRole , DisplayRole , FontRole , DecorationRole , ForegroundRole ,和 BackgroundRole .
注意: 每个头为每区间本身渲染数据,且不依赖委托。因此,调用头的 setItemDelegate () 函数不起作用。
另请参阅 模型/视图编程 , QListView , QTableView ,和 QTreeView .
重置尺寸模式指定头区间的行为。可以被设置在整个头视图或单个区间使用 setSectionResizeMode ().
常量 | 值 | 描述 |
---|---|---|
QHeaderView::Interactive
|
0
|
用户可以调整区间大小。也可以按编程方式调整区间大小使用 resizeSection ()。区间尺寸默认为 defaultSectionSize 。(另请参阅 cascadingSectionResizes .) |
QHeaderView::Fixed
|
2
|
用户无法调整区间大小。只可以按编程方式调整区间大小使用 resizeSection ()。区间尺寸默认为 defaultSectionSize . |
QHeaderView::Stretch
|
1
|
QHeaderView 会自动重置区间大小以填充可用空间。用户 (或以编程方式) 无法改变大小。 |
QHeaderView::ResizeToContents
|
3
|
QHeaderView 将基于整列 (或整行) 内容自动把区间尺寸调整到最优大小。尺寸无法被改变由用户或按编程方式。(该值在 4.2 引入) |
以下值已过时:
常量 | 值 | 描述 |
---|---|---|
QHeaderView::Custom
|
Fixed
|
使用 Fixed 代替。 |
另请参阅 setSectionResizeMode (), stretchLastSection ,和 minimumSectionSize .
此特性保持一旦用户调整区间大小到达最小尺寸时是否就把交互重置尺寸级联到紧随区间
此特性只影响区间拥有 Interactive 作为其重置尺寸模式。
默认值为 false。
访问函数:
bool | cascadingSectionResizes () const |
void | setCascadingSectionResizes (bool enable ) |
另请参阅 setSectionResizeMode ().
此特性保持在每个头区间中文本的默认对齐方式
访问函数:
Qt::Alignment | defaultAlignment () const |
void | setDefaultAlignment (Qt::Alignment alignment ) |
此特性保持头区间的默认大小,在重置尺寸之前。
此特性只影响区间拥有 Interactive or Fixed 作为其重置尺寸模式。
默认情况下,此特性的值从属样式。因此,当样式改变时,此特性随之更新。调用 setDefaultSectionSize() 停止更新,调用 resetDefaultSectionSize() 将还原默认行为。
访问函数:
int | defaultSectionSize () const |
void | setDefaultSectionSize (int size ) |
void | resetDefaultSectionSize () |
另请参阅 setSectionResizeMode () 和 minimumSectionSize .
[since 5.11]
firstSectionMovable
:
bool
此特性保持用户是否可以移动第一列
此特性控制用户是否可以移动第一列。在 QTreeView , the first column holds the tree structure and is therefore non-movable by default, even after setSectionsMovable (true)。
It can be made movable again, for instance in the case of flat lists without a tree structure, by calling this method. In such a scenario, it is recommended to call QTreeView::setRootIsDecorated (false) as well.
Setting it to true has no effect unless setSectionsMovable (true) is called as well.
该特性在 Qt 5.11 引入。
访问函数:
bool | isFirstSectionMovable () const |
void | setFirstSectionMovable (bool movable ) |
另请参阅 setSectionsMovable ().
此特性保持包含选中项的区间是否被突显
默认情况下,此特性为
false
.
访问函数:
bool | highlightSections () const |
void | setHighlightSections (bool highlight ) |
[since 5.2]
maximumSectionSize
:
int
此特性保持头区间的最大尺寸。
最大区间尺寸是允许的最大区间尺寸。此特性的默认值为 1048575,也是区间的最大可能尺寸。把最大设为 -1 将重置尺寸值到最大区间尺寸。
除拉伸外,此特性被承兑由所有 重置大小模式
该特性在 Qt 5.2 引入。
访问函数:
int | maximumSectionSize () const |
void | setMaximumSectionSize (int size ) |
另请参阅 setSectionResizeMode () 和 defaultSectionSize .
此特性保持头区间的最小尺寸。
最小区间尺寸是允许的最小区间尺寸。若最小区间尺寸被设为 -1, QHeaderView will use the 字体规格 尺寸。
此特性被承兑由所有 重置大小模式 .
访问函数:
int | minimumSectionSize () const |
void | setMinimumSectionSize (int size ) |
另请参阅 setSectionResizeMode () 和 defaultSectionSize .
此特性保持是否展示排序指示器
默认情况下,此特性为
false
.
访问函数:
bool | isSortIndicatorShown () const |
void | setSortIndicatorShown (bool show ) |
另请参阅 setSectionsClickable ().
[since 6.1]
sortIndicatorClearable
:
bool
This property holds whether the sort indicator can be cleared by clicking on a section multiple times
This property controls whether the user is able to remove the sorting indicator on a given section by clicking on the section multiple times. Normally, clicking on a section will simply change the sorting order for that section. By setting this property to true, the sorting indicator will be cleared after alternating to ascending and descending; this will typically restore the original sorting of a model.
Setting this property to true has no effect unless sectionsClickable () is also true (which is the default for certain views, for instance QTableView , or is automatically set when making a view sortable, for instance by calling QTreeView::setSortingEnabled ).
This property was introduced in Qt 6.1.
访问函数:
bool | isSortIndicatorClearable () const |
void | setSortIndicatorClearable (bool clearable ) |
通知程序信号:
void | sortIndicatorClearableChanged (bool clearable ) |
此特性保持 Header (头) 中的最后一个可见区间是否占用所有可用空间
默认值为 false。
注意: 水平头提供由 QTreeView 此特性配置被设为 true,确保视图不浪费为其 Header 头部赋值的任何空间。若此值被设为 true,此特性将覆盖 Header 头部最后区间设置的重置尺寸模式。
访问函数:
bool | stretchLastSection () const |
void | setStretchLastSection (bool stretch ) |
另请参阅 setSectionResizeMode ().
创建新通用头采用给定 orientation and parent .
[signal]
void
QHeaderView::
geometriesChanged
()
此信号被发射当头几何体有改变时。
[slot]
void
QHeaderView::
headerDataChanged
(
Qt::Orientation
orientation
,
int
logicalFirst
,
int
logicalLast
)
更新改变头区间采用给定 orientation ,从 logicalFirst to logicalLast 包括在内。
[protected slot]
void
QHeaderView::
resizeSections
()
调整区间大小根据其大小提示。通常,不必调用此函数。
[signal]
void
QHeaderView::
sectionClicked
(
int
logicalIndex
)
此信号被发射当点击区间时。区间逻辑索引指定由 logicalIndex .
注意, sectionPressed 信号也会被发射。
另请参阅 setSectionsClickable () 和 sectionPressed ().
[signal]
void
QHeaderView::
sectionCountChanged
(
int
oldCount
,
int
newCount
)
This signal is emitted when the number of sections changes, i.e., when sections are added or deleted. The original count is specified by oldCount , and the new count by newCount .
另请参阅 count (), length (),和 headerDataChanged ().
[signal]
void
QHeaderView::
sectionDoubleClicked
(
int
logicalIndex
)
This signal is emitted when a section is double-clicked. The section's logical index is specified by logicalIndex .
另请参阅 setSectionsClickable ().
[signal]
void
QHeaderView::
sectionEntered
(
int
logicalIndex
)
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 .
另请参阅 setSectionsClickable () 和 sectionPressed ().
[signal]
void
QHeaderView::
sectionHandleDoubleClicked
(
int
logicalIndex
)
This signal is emitted when a section is double-clicked. The section's logical index is specified by logicalIndex .
另请参阅 setSectionsClickable ().
[signal]
void
QHeaderView::
sectionMoved
(
int
logicalIndex
,
int
oldVisualIndex
,
int
newVisualIndex
)
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 ().
[signal]
void
QHeaderView::
sectionPressed
(
int
logicalIndex
)
This signal is emitted when a section is pressed. The section's logical index is specified by logicalIndex .
另请参阅 setSectionsClickable ().
[signal]
void
QHeaderView::
sectionResized
(
int
logicalIndex
,
int
oldSize
,
int
newSize
)
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 ().
[protected slot]
void
QHeaderView::
sectionsAboutToBeRemoved
(const
QModelIndex
&
parent
,
int
logicalFirst
,
int
logicalLast
)
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.
[protected slot]
void
QHeaderView::
sectionsInserted
(const
QModelIndex
&
parent
,
int
logicalFirst
,
int
logicalLast
)
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.
[slot]
void
QHeaderView::
setOffset
(
int
offset
)
把 Header 头部偏移设为 offset .
[slot]
void
QHeaderView::
setOffsetToLastSection
()
设置偏移以使最后区间可见。
另请参阅 setOffset (), sectionPosition (),和 setOffsetToSectionPosition ().
[slot]
void
QHeaderView::
setOffsetToSectionPosition
(
int
visualSectionNumber
)
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 ().
另请参阅 setOffset () 和 sectionPosition ().
[signal]
void
QHeaderView::
sortIndicatorChanged
(
int
logicalIndex
,
Qt::SortOrder
order
)
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 specified by order .
另请参阅 setSortIndicator ().
[virtual]
QHeaderView::
~QHeaderView
()
销毁 Header 头。
返回 Header 头的区间数。
另请参阅 sectionCountChanged () 和 length ().
[override virtual protected]
void
QHeaderView::
currentChanged
(const
QModelIndex
&
current
, const
QModelIndex
&
old
)
重实现: QAbstractItemView::currentChanged (const QModelIndex ¤t, const QModelIndex &previous).
[override virtual protected]
bool
QHeaderView::
event
(
QEvent
*
e
)
重实现: QAbstractItemView::event (QEvent *event).
返回已隐藏的头区间数。
另请参阅 setSectionHidden () 和 isSectionHidden ().
隐藏区间指定通过 logicalIndex .
另请参阅 showSection (), isSectionHidden (), hiddenSectionCount (),和 setSectionHidden ().
[override virtual protected]
int
QHeaderView::
horizontalOffset
() const
重实现: QAbstractItemView::horizontalOffset () const.
返回 Header 头部的水平偏移。这为 0 对于垂直头部。
另请参阅 offset ().
[virtual protected]
void
QHeaderView::
initStyleOption
(
QStyleOptionHeader
*
option
) const
初始化 option 采用值来自此 QHeaderView 。此方法对子类是有用的,当需要 QStyleOptionHeader ,但不想自己填充所有信息。
另请参阅 QStyleOption::initFrom () 和 initStyleOptionForIndex ().
[virtual protected, since 6.0]
void
QHeaderView::
initStyleOptionForIndex
(
QStyleOptionHeader
*
option
,
int
logicalIndex
) const
Initializes the style option 从指定 logicalIndex . This function is called by the default implementation of paintSection after initStyleOption has been called.
该函数在 Qt 6.0 引入。
另请参阅 paintSection () 和 initStyleOption ().
返回
true
if the section specified by
logicalIndex
is explicitly hidden from the user; otherwise returns
false
.
另请参阅 hideSection (), showSection (), setSectionHidden (),和 hiddenSectionCount ().
返回沿 Header 头方向的长度。
另请参阅 sizeHint (), setSectionResizeMode (),和 offset ().
Returns the logicalIndex for the section at the given visualIndex position, or -1 if visualIndex < 0 or visualIndex >= QHeaderView::count ().
注意, visualIndex is not affected by hidden sections.
另请参阅 visualIndex () 和 sectionPosition ().
Returns the section that covers the given position in the 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 ().
[override virtual protected]
void
QHeaderView::
mouseDoubleClickEvent
(
QMouseEvent
*
e
)
重实现: QAbstractItemView::mouseDoubleClickEvent (QMouseEvent *event).
[override virtual protected]
void
QHeaderView::
mouseMoveEvent
(
QMouseEvent
*
e
)
重实现: QAbstractItemView::mouseMoveEvent (QMouseEvent *event).
[override virtual protected]
void
QHeaderView::
mousePressEvent
(
QMouseEvent
*
e
)
重实现: QAbstractItemView::mousePressEvent (QMouseEvent *event).
[override virtual protected]
void
QHeaderView::
mouseReleaseEvent
(
QMouseEvent
*
e
)
重实现: QAbstractItemView::mouseReleaseEvent (QMouseEvent *event).
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 .
[override virtual protected]
void
QHeaderView::
paintEvent
(
QPaintEvent
*
e
)
重实现: QAbstractScrollArea::paintEvent (QPaintEvent *event).
[virtual protected]
void
QHeaderView::
paintSection
(
QPainter
*
painter
, const
QRect
&
rect
,
int
logicalIndex
) const
Paints the section specified by the given logicalIndex ,使用给定 painter and rect .
通常,不必调用此函数。
[override virtual]
void
QHeaderView::
reset
()
重实现: QAbstractItemView::reset ().
[since 5.2]
int
QHeaderView::
resizeContentsPrecision
() const
Returns how precise QHeaderView will calculate on ResizeToContents .
该函数在 Qt 5.2 引入。
另请参阅 setResizeContentsPrecision () 和 setSectionResizeMode ().
重置区间大小指定通过 logicalIndex to size 度量 (以像素为单位)。尺寸参数必须是 >= 0 的值。不管怎样,不推荐 size 等于 0。在此情况下 hideSection 应该被使用以取而代之。
另请参阅 sectionResized (), sectionSize (),和 hideSection ().
Resizes the sections according to the given mode , ignoring the current resize mode.
另请参阅 sectionResized ().
Restores the
state
of this header view. This function returns
true
if the state was restored; otherwise returns false.
另请参阅 saveState ().
保存此头视图的当前状态。
要还原保存状态,把返回值传递给 restoreState ().
另请参阅 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 ().
[since 5.0]
QHeaderView::ResizeMode
QHeaderView::
sectionResizeMode
(
int
logicalIndex
) const
Returns the resize mode that applies to the section specified by the given logicalIndex .
该函数在 Qt 5.0 引入。
另请参阅 setSectionResizeMode ().
Returns the width (or height for vertical headers) of the given logicalIndex .
另请参阅 length (), setSectionResizeMode (),和 defaultSectionSize ().
[virtual protected]
QSize
QHeaderView::
sectionSizeFromContents
(
int
logicalIndex
) const
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 (),和 maximumSectionSize ().
Returns the section viewport position of the given logicalIndex .
如果区间被隐藏,返回值不确定。
另请参阅 sectionPosition () 和 isSectionHidden ().
[since 5.0]
bool
QHeaderView::
sectionsClickable
() const
返回
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.
该函数在 Qt 5.0 引入。
另请参阅 setSectionsClickable ().
返回
true
若 Header 头区间被隐藏;否则返回 false;
另请参阅 setSectionHidden ().
[since 5.0]
bool
QHeaderView::
sectionsMovable
() const
返回
true
若 Header 头可以被用户移动;否则返回 false。
By default, sections are movable in QTreeView (except for the first one), and not movable in QTableView .
该函数在 Qt 5.0 引入。
另请参阅 setSectionsMovable ().
返回
true
若 Header 头区间已被移动;否则返回 false;
另请参阅 moveSection ().
[override virtual]
void
QHeaderView::
setModel
(
QAbstractItemModel
*
model
)
重实现: QAbstractItemView::setModel (QAbstractItemModel *model).
[since 5.2]
void
QHeaderView::
setResizeContentsPrecision
(
int
precision
)
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 QTableView::sizeHintForColumn (), QTableView::sizeHintForRow () 和 QTreeView::sizeHintForColumn (). Reimplementing these functions can make this function not having an effect.
该函数在 Qt 5.2 引入。
另请参阅 resizeContentsPrecision (), setSectionResizeMode (), resizeSections (), QTableView::sizeHintForColumn (), QTableView::sizeHintForRow (),和 QTreeView::sizeHintForColumn ().
若 hide 为 true 区间指定通过 logicalIndex 被隐藏;否则展示区间。
另请参阅 isSectionHidden () 和 hiddenSectionCount ().
[since 5.0]
void
QHeaderView::
setSectionResizeMode
(
QHeaderView::ResizeMode
mode
)
设置如何把头重置到哪些描述大小的约束通过给定 mode .
该函数在 Qt 5.0 引入。
另请参阅 sectionResizeMode (), length (),和 sectionResized ().
[since 5.0]
void
QHeaderView::
setSectionResizeMode
(
int
logicalIndex
,
QHeaderView::ResizeMode
mode
)
设置区间如何被约束指定通过 logicalIndex 在头中可以重置到那些描述大小通过给定 mode 。逻辑索引应该存在,当此函数被调用时。
注意: 最后区间会忽略此设置若 stretchLastSection 特性被设为 true。这是默认的对于水平头提供通过 QTreeView .
该函数在 Qt 5.0 引入。
另请参阅 setStretchLastSection () 和 resizeContentsPrecision ().
[since 5.0]
void
QHeaderView::
setSectionsClickable
(
bool
clickable
)
若 clickable 为 true,头将响应单击。
该函数在 Qt 5.0 引入。
另请参阅 sectionsClickable (), sectionClicked (), sectionPressed (),和 setSortIndicatorShown ().
[since 5.0]
void
QHeaderView::
setSectionsMovable
(
bool
movable
)
若 movable 为 true,用户可以移动 Header 头区间;否则,它们被固定在原地。
当组合使用同 QTreeView ,第一列是不可移动的 (因为它包含树结构) 默认情况下。可以使之可移动采用 setFirstSectionMovable (true)。
该函数在 Qt 5.0 引入。
另请参阅 sectionsMovable (), sectionMoved (),和 setFirstSectionMovable ().
[override virtual protected]
void
QHeaderView::
setSelection
(const
QRect
&
rect
,
QItemSelectionModel::SelectionFlags
flags
)
重实现: QAbstractItemView::setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags flags).
Selects the items in the given rect 根据指定 flags .
基类实现什么都不做。
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.
另请参阅 sortIndicatorSection () 和 sortIndicatorOrder ().
[override virtual]
void
QHeaderView::
setVisible
(
bool
v
)
重实现访问函数为特性: QWidget::visible .
显示指定区间通过 logicalIndex .
另请参阅 hideSection (), isSectionHidden (), hiddenSectionCount (),和 setSectionHidden ().
[override virtual]
QSize
QHeaderView::
sizeHint
() const
重实现: QAbstractScrollArea::sizeHint () const.
返回此 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 (),和 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.
另请参阅 stretchLastSection .
Swaps the section at visual index first with the section at visual index second .
另请参阅 moveSection ().
[override virtual protected]
int
QHeaderView::
verticalOffset
() const
重实现: QAbstractItemView::verticalOffset () const.
Returns the vertical offset of the header. This is 0 for horizontal headers.
另请参阅 offset ().
[override virtual protected]
bool
QHeaderView::
viewportEvent
(
QEvent
*
e
)
重实现: QAbstractItemView::viewportEvent (QEvent *event).
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 ().