QHeaderView Class

QHeaderView 类为项目视图提供标题行或标题列。更多

标题 #include <QHeaderView>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
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(const QPoint &pos) const
int logicalIndexAt(int position) const
int logicalIndexAt(int x, int y) 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
(since 6.0) 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 显示项目视图(如QTableViewQTreeView 类)中使用的标题。它取代了之前用于相同目的的 Qt3 的QHeader 类,但使用了 Qt 的模型/视图架构,以便与项目视图类保持一致。

QHeaderView 类是模型/视图类之一,也是 Qt模型/视图框架的一部分。

页眉使用QAbstractItemModel::headerData() 函数从模型中获取各部分的数据。您可以使用QAbstractItemModel::setHeaderData() 设置数据。

每个页眉都有一个orientation() 和若干部分,由count() 函数给出。部分指的是标题的一部分--根据方向的不同,可以是一行或一列。

可以使用moveSection() 和resizeSection() 移动和调整节的大小;还可以使用hideSection() 和showSection() 隐藏和显示节。

页眉的每个部分都有一个部分 ID,由其部分()指定,并可位于页眉中的特定visualIndex() 处。节可以使用setSortIndicator() 设置排序指示符;这表示相关项目视图中的项目是否按节给出的顺序排序。

对于水平标题,节相当于模型中的一列,而对于垂直标题,节相当于模型中的一行。

移动页眉部分

标题可以固定在原处,也可以通过setSectionsMovable() 移动。使用setSectionsClickable() 可以点击标题,使用setSectionResizeMode() 可以调整标题的大小。

注意: 双击页眉以调整部分大小只适用于可见行。

如果用户移动部分,页眉将发出sectionMoved() 信号;如果用户调整部分大小,页眉将发出sectionResized() 信号;如果用户点击鼠标,页眉将发出sectionClicked() 和sectionHandleDoubleClicked() 信号。页眉也会发出sectionCountChanged() 。

您可以使用logicalIndex() 和logicalIndexAt() 函数,或使用visualIndex() 和visualIndexAt() 函数,通过索引位置来识别一个部分。如果移动了一个部分,视觉索引会改变,但逻辑索引不会改变。

外观

QTableWidget 和 创建默认页眉。如果希望标题可见,可以使用 () 。QTableView setVisible

并非所有ItemDataRole都会对 QHeaderView 产生影响。如果需要绘制其他角色,可以子类化 QHeaderView 并重新实现paintEvent() 。QHeaderView 尊重以下项目数据角色,除非它们与样式冲突(这可能发生在遵循桌面主题的样式中):

TextAlignmentRole,DisplayRole,FontRole,DecorationRole,ForegroundRole, 和BackgroundRole

注意: 每个页眉都自行渲染各部分的数据,而不依赖委托。因此,调用标题的setItemDelegate() 函数不会有任何效果。

巨型模型的特殊考虑

头视图每个部分使用 8 至 16 字节内存。不过,自 Qt 6.9 起,只有在一个或多个部分被调整大小或重新排序时,才会使用这些部分内存。这意味着,只要调用swapSections,resizeSection,hideSection,moveSection, 和stretchLastSection (启用它),一个模型就有可能拥有数百万个部分,而 QHeaderView 不会按比例消耗大量内存。为了避免用户操作对resize mode 的调用,应将Fixed (不要为任何索引指定它,因为这样做会适得其反)。此外,还应禁用sectionsMovable ,以防止用户移动部分。

另请参阅 模型/视图编程QListViewQTableViewQTreeView

成员类型文档

enum QHeaderView::ResizeMode

调整大小模式指定标题部分的行为。可以使用setSectionResizeMode() 对整个标题视图或单个部分进行设置。

常数说明
QHeaderView::Interactive0用户可以调整标题部分的大小。也可以使用resizeSection() 通过编程调整部分大小。部分大小默认为defaultSectionSize 。(另请参阅cascadingSectionResizes 。)
QHeaderView::Fixed2用户不能调整版块大小。只能通过resizeSection() 以编程方式调整部分大小。部分大小默认为defaultSectionSize
QHeaderView::Stretch1QHeaderView 将自动调整版块大小以填充可用空间。用户或程序均无法更改大小。
QHeaderView::ResizeToContents3QHeaderView 将根据整列或整行的内容自动调整部分的大小,使其达到最佳尺寸。用户或程序均无法更改大小。(此值在 4.2 中引入)

以下值已过时:

常量说明
QHeaderView::CustomFixed使用固定值。

另请参阅 setSectionResizeMode(),stretchLastSection, 和minimumSectionSize

属性文档

cascadingSectionResizes : bool

此属性用于确定当用户正在调整大小的部分达到最小大小时,交互式大小调整是否会级联到以下部分

该属性只影响以Interactive 作为调整大小模式的部分。

默认值为 false。

访问功能:

bool cascadingSectionResizes() const
void setCascadingSectionResizes(bool enable)

另请参阅 setSectionResizeMode().

defaultAlignment : Qt::Alignment

该属性保存每个标题部分文本的默认对齐方式

访问功能:

Qt::Alignment defaultAlignment() const
void setDefaultAlignment(Qt::Alignment alignment)

defaultSectionSize : int

此属性保留调整大小前标题部分的默认大小。

该属性只影响以InteractiveFixed 作为调整大小模式的部分。

默认情况下,该属性的值取决于样式。因此,当样式发生变化时,该属性也会随之更新。调用 setDefaultSectionSize() 会停止更新,调用 resetDefaultSectionSize() 则会恢复默认行为。

访问函数:

int defaultSectionSize() const
void setDefaultSectionSize(int size)
void resetDefaultSectionSize()

另请参见 setSectionResizeMode() 和minimumSectionSize

firstSectionMovable : bool

该属性控制用户是否可以移动第一列

该属性控制用户是否可以移动第一列。在QTreeView 中,第一列是树形结构,因此默认情况下是不可移动的,即使在setSectionsMovable(true) 之后也是如此。

例如,在没有树形结构的扁平列表中,可以通过调用此方法使其再次可移动。在这种情况下,建议同时调用QTreeView::setRootIsDecorated(false)。

treeView->setRootIsDecorated(false);
treeView->header()->setFirstSectionMovable(true);

除非同时调用setSectionsMovable(true),否则将其设置为 true 没有任何作用。

访问函数:

bool isFirstSectionMovable() const
void setFirstSectionMovable(bool movable)

另请参见 setSectionsMovable()。

highlightSections : bool

此属性表示是否高亮显示包含选定项目的部分

默认情况下,此属性为false

访问功能:

bool highlightSections() const
void setHighlightSections(bool highlight)

maximumSectionSize : int

该属性用于保存标题部分的最大尺寸。

最大分段大小是允许的最大分段大小。该属性的默认值为 1048575,这也是可能的最大分区大小。将最大值设置为-1 将重置该值为最大分区大小。

除拉伸外,所有resize modes

访问函数都会遵守该属性:

int maximumSectionSize() const
void setMaximumSectionSize(int size)

另请参阅 setSectionResizeMode() 和defaultSectionSize

minimumSectionSize : int

该属性用于保存标题部分的最小尺寸。

最小部分大小是允许的最小部分大小。如果将最小部分大小设为-1,QHeaderView 将使用font metrics 大小。

所有resize modes 都遵守此属性。

访问函数:

int minimumSectionSize() const
void setMinimumSectionSize(int size)

另请参阅 setSectionResizeMode() 和defaultSectionSize

sectionsClickable : bool

如果页眉可点击,则保持true ;否则保持false 。可点击的页眉可以让用户更改与页眉相关的视图中的数据表示。

访问功能:

bool sectionsClickable() const
void setSectionsClickable(bool clickable)

另请参阅 sectionPressed() 和setSortIndicatorShown()。

sectionsMovable : bool

如果sectionsMovable 为 true,则标题部分可由用户移动;否则将固定在原处。

QTreeView 结合使用时,默认情况下第一列不可移动(因为它包含树形结构)。您可以使用setFirstSectionMovable(true) 使其可移动。

访问功能:

bool sectionsMovable() const
void setSectionsMovable(bool movable)

另请参见 sectionMoved() 和setFirstSectionMovable()。

showSortIndicator : bool

该属性表示是否显示排序指示符

默认情况下,该属性为false

访问函数:

bool isSortIndicatorShown() const
void setSortIndicatorShown(bool show)

另请参阅 setSectionsClickable() 。

[since 6.1] sortIndicatorClearable : bool

该属性用于控制是否可以通过多次点击某个部分来清除排序指示符。

该属性控制用户是否可以通过多次点击给定部分来移除该部分的排序指示符。通常情况下,点击某个部分只会改变该部分的排序顺序。将此属性设置为 true 后,排序指示符将在升序和降序交替后被清除;这通常会恢复模型的原始排序。

除非sectionsClickable() 也为 true(这是某些视图的默认设置,例如QTableView ,或者在使视图可排序时自动设置,例如调用QTreeView::setSortingEnabled ),否则将此属性设置为 true 没有任何作用。

该属性在 Qt 6.1 中引入。

访问函数:

bool isSortIndicatorClearable() const
void setSortIndicatorClearable(bool clearable)

Notifier 信号:

void sortIndicatorClearableChanged(bool clearable)

stretchLastSection : bool

该属性用于确定标题中最后一个可见部分是否占用了所有可用空间

默认值为 false。

注: QTreeView 提供的水平页眉在配置时将此属性设置为 true,以确保视图不会浪费为其页眉分配的任何空间。如果该值设置为 true,该属性将覆盖页眉最后部分的大小调整模式。

访问功能:

bool stretchLastSection() const
void setStretchLastSection(bool stretch)

另请参阅 setSectionResizeMode().

成员函数文档

[explicit] QHeaderView::QHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr)

使用给定的orientationparent 创建新的通用标头。

[virtual noexcept] QHeaderView::~QHeaderView()

破坏头像。

int QHeaderView::count() const

返回页眉中的章节数量。

另请参阅 sectionCountChanged() 和length()。

[override virtual protected] void QHeaderView::currentChanged(const QModelIndex &current, const QModelIndex &old)

重实现:QAbstractItemView::currentChanged(const QModelIndex &current, const QModelIndex &previous).

[override virtual protected] bool QHeaderView::event(QEvent *e)

重实现:QAbstractItemView::event(QEvent *event).

[signal] void QHeaderView::geometriesChanged()

当标头的几何形状发生变化时会发出该信号。

[slot] void QHeaderView::headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast)

用给定的orientation 更新已更改的页眉部分,从logicalFirstlogicalLast (含)。

int QHeaderView::hiddenSectionCount() const

返回页眉中被隐藏的部分的数目。

另请参阅 setSectionHidden() 和isSectionHidden()。

void QHeaderView::hideSection(int logicalIndex)

隐藏logicalIndex 指定的部分。

另请参阅 showSection()、isSectionHidden()、hiddenSectionCount() 和setSectionHidden() 。

[override virtual protected] int QHeaderView::horizontalOffset() const

重实现:QAbstractItemView::horizontalOffset() 常量。

返回页眉的水平偏移量。垂直标题的偏移量为 0。

另请参阅 offset().

[virtual protected] void QHeaderView::initStyleOption(QStyleOptionHeader *option) const

使用本QHeaderView 中的值初始化option 。当子类需要QStyleOptionHeader ,但又不想自己填写所有信息时,该方法非常有用。

另请参阅 QStyleOption::initFrom() 和initStyleOptionForIndex()。

[virtual protected, since 6.0] void QHeaderView::initStyleOptionForIndex(QStyleOptionHeader *option, int logicalIndex) const

从指定的logicalIndex 初始化样式optionpaintSection 的默认实现会在调用initStyleOption 后调用该函数。

该函数在 Qt 6.0 中引入。

另请参阅 paintSection() 和initStyleOption()。

bool QHeaderView::isSectionHidden(int logicalIndex) const

如果logicalIndex 所指定的部分对用户明确隐藏,则返回true ;否则返回false

另请参阅 hideSection()、showSection()、setSectionHidden() 和hiddenSectionCount()。

int QHeaderView::length() const

返回页眉方向的长度。

另请参阅 sizeHint()、setSectionResizeMode() 和offset()。

int QHeaderView::logicalIndex(int visualIndex) const

返回位于给定visualIndex 位置的部分的 logicalIndex,如果visualIndex < 0 或visualIndex >=QHeaderView::count() 则返回-1。

请注意,visualIndex 不受隐藏部分的影响。

另请参阅 visualIndex() 和sectionPosition()。

int QHeaderView::logicalIndexAt(const QPoint &pos) const

返回pos 中给定位置的部分的逻辑索引。如果页眉是水平的,则使用 x 坐标,否则使用 y 坐标查找逻辑索引。

另请参见 sectionPosition()。

int QHeaderView::logicalIndexAt(int position) const

返回视口中覆盖给定position 的部分。

另请参阅 visualIndexAt() 和isSectionHidden()。

int QHeaderView::logicalIndexAt(int x, int y) const

返回位于给定坐标处的部分的逻辑索引。如果页眉是水平的,x ,否则将使用y 查找逻辑索引。

[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).

void QHeaderView::moveSection(int from, int to)

将位于视觉索引from 的部分移动到占用视觉索引to 的位置。

另请参阅 sectionsMoved() 。

int QHeaderView::offset() const

返回页眉的偏移量:这是页眉最左边(或垂直页眉的最上层)的可见像素。

另请参见 setOffset()。

Qt::Orientation QHeaderView::orientation() const

返回页眉的方向。

另请参见 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

使用给定的painterrect 绘制由给定的logicalIndex 指定的部分。

通常情况下,您无需调用此函数。

[override virtual] void QHeaderView::reset()

重新实现:QAbstractItemView::reset().

int QHeaderView::resizeContentsPrecision() const

返回QHeaderViewResizeToContents 上的计算精确度。

另请参见 setResizeContentsPrecision() 和setSectionResizeMode()。

void QHeaderView::resizeSection(int logicalIndex, int size)

logicalIndex 指定的部分大小调整为size ,单位为像素。尺寸参数的值必须大于或等于零。但不建议使用等于零的大小。在这种情况下,应使用hideSection

另请参阅 sectionResized(),sectionSize() 和hideSection()。

[protected slot] void QHeaderView::resizeSections()

根据大小提示调整各部分的大小。通常情况下,无需调用此函数。

void QHeaderView::resizeSections(QHeaderView::ResizeMode mode)

根据给定的mode 调整各部分的大小,忽略当前的大小调整模式。

另请参阅 sectionResized().

bool QHeaderView::restoreState(const QByteArray &state)

恢复该标题视图的state 。如果状态已恢复,该函数返回true ;否则返回 false。

另请参见 saveState().

QByteArray QHeaderView::saveState() const

保存此标题视图的当前状态。

要恢复已保存的状态,请将返回值传递给restoreState() 。

另请参阅 restoreState() 。

[signal] void QHeaderView::sectionClicked(int logicalIndex)

当点击某个部分时会发出该信号。该部分的逻辑索引由logicalIndex 指定。

请注意,sectionPressed 信号也会发出。

另请参阅 setSectionsClickable() 和sectionPressed()。

[signal] void QHeaderView::sectionCountChanged(int oldCount, int newCount)

当章节数量发生变化时,即添加或删除章节时,会发出该信号。原计数由oldCount 指定,新计数由newCount 指定。

另请参见 count()、length() 和headerDataChanged()。

[signal] void QHeaderView::sectionDoubleClicked(int logicalIndex)

双击某个部分时会发出该信号。节的逻辑索引由logicalIndex 指定。

另请参阅 setSectionsClickable() 。

[signal] void QHeaderView::sectionEntered(int logicalIndex)

当光标移动到节上并按下鼠标左键时,就会发出该信号。节的逻辑索引由logicalIndex 指定。

另请参阅 setSectionsClickable() 和sectionPressed()。

[signal] void QHeaderView::sectionHandleDoubleClicked(int logicalIndex)

双击某个部分时会发出该信号。节的逻辑索引由logicalIndex 指定。

另请参阅 setSectionsClickable() 。

[signal] void QHeaderView::sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex)

该信号在移动分节时发出。该部分的逻辑索引由logicalIndex 指定,旧索引由oldVisualIndex 指定,新索引位置由newVisualIndex 指定。

另请参见 moveSection() 。

int QHeaderView::sectionPosition(int logicalIndex) const

返回给定logicalIndex 的分区位置,如果分区被隐藏,则返回-1。位置以像素为单位,从第一个可见项的左上角到logicalIndex 项的左上角。水平标题的测量值沿 x 轴,垂直标题的测量值沿 y 轴。

另请参见 sectionViewportPosition()。

[signal] void QHeaderView::sectionPressed(int logicalIndex)

当按下某个部分时会发出该信号。节的逻辑索引由logicalIndex 指定。

另请参阅 setSectionsClickable() 。

QHeaderView::ResizeMode QHeaderView::sectionResizeMode(int logicalIndex) const

返回适用于给定logicalIndex 所指定部分的调整大小模式。

另请参阅 setSectionResizeMode()。

[signal] void QHeaderView::sectionResized(int logicalIndex, int oldSize, int newSize)

该信号在调整部分大小时发出。该部分的逻辑编号由logicalIndex 指定,旧尺寸由oldSize 指定,新尺寸由newSize 指定。

另请参阅 resizeSection() 。

int QHeaderView::sectionSize(int logicalIndex) const

返回给定logicalIndex 的宽度(或垂直标题的高度)。

另请参阅 length()、setSectionResizeMode() 和defaultSectionSize()。

[virtual protected] QSize QHeaderView::sectionSizeFromContents(int logicalIndex) const

返回logicalIndex 指定的部分内容的大小。

另请参阅 defaultSectionSize() 。

int QHeaderView::sectionSizeHint(int logicalIndex) const

logicalIndex 指定的部分返回合适的大小提示。

Qt::SizeHintRole

另请参阅 sizeHint(),defaultSectionSize(),minimumSectionSize() 和maximumSectionSize().

int QHeaderView::sectionViewportPosition(int logicalIndex) const

返回给定logicalIndex 的部分视口位置。

如果部分是隐藏的,则返回值未定义。

另请参阅 sectionPosition() 和isSectionHidden()。

[protected slot] void QHeaderView::sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast)

parent 中的部分被删除时,会调用此槽。logicalFirstlogicalLast 表示部分被删除的位置。

如果只删除了一个部分,logicalFirstlogicalLast 将保持不变。

bool QHeaderView::sectionsClickable() const

返回 sectionsClickable。

注: 属性 sectionsClickable 的获取函数。

另请参阅 setSectionsClickable().

bool QHeaderView::sectionsHidden() const

如果页眉中的部分已被隐藏,则返回true ;否则返回 false;

另请参见 setSectionHidden().

[protected slot] void QHeaderView::sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast)

parent 中插入章节时调用此槽。logicalFirstlogicalLast 表示新章节插入的位置。

如果只插入了一个部分,logicalFirstlogicalLast 将是相同的。

bool QHeaderView::sectionsMovable() const

返回 sectionsMovable。

注: 属性 sectionsMovable 的获取函数。

另请参阅 setSectionsMovable().

bool QHeaderView::sectionsMoved() const

如果标题中的部分已被移动,则返回true ;否则返回 false;

另请参见 moveSection().

[override virtual] void QHeaderView::setModel(QAbstractItemModel *model)

重实现:QAbstractItemView::setModel(QAbstractItemModel *model).

[slot] void QHeaderView::setOffset(int offset)

将标头偏移量设置为offset

另请参阅 offset() 和length()。

[slot] void QHeaderView::setOffsetToLastSection()

设置偏移量,使最后一节可见。

另请参阅 setOffset()、sectionPosition() 和setOffsetToSectionPosition()。

[slot] void QHeaderView::setOffsetToSectionPosition(int visualSectionNumber)

在给定的visualSectionNumber 处设置偏移到部分的起始位置。当不考虑 hiddenSections 时,visualSectionNumber 是实际可见的部分。这并不总是与visualIndex() 相同。

另请参阅 setOffset() 和sectionPosition()。

void QHeaderView::setResizeContentsPrecision(int precision)

设置QHeaderView 在使用ResizeToContents 时计算大小的精确度。数值越小,自动调整大小的精度越低,但速度越快;数值越大,自动调整大小的精度越高,但速度越慢。

数字precision 用于指定在计算首选大小时应考虑多少部分。

默认值为 1000,这意味着使用自动调整大小功能的横向列在进行自动调整大小时最多只能计算 1000 行。

特殊值 0 表示只查看可见区域。特殊值-1 表示查看所有元素。

该值在QTableView::sizeHintForColumn(),QTableView::sizeHintForRow() 和QTreeView::sizeHintForColumn() 中使用。重新实现这些函数会使该函数不起作用。

另请参见 resizeContentsPrecision()、setSectionResizeMode()、resizeSections()、QTableView::sizeHintForColumn()、QTableView::sizeHintForRow() 和QTreeView::sizeHintForColumn()。

void QHeaderView::setSectionHidden(int logicalIndex, bool hide)

如果hide 为真,则隐藏logicalIndex 指定的部分;否则显示该部分。

另请参阅 isSectionHidden() 和hiddenSectionCount()。

void QHeaderView::setSectionResizeMode(QHeaderView::ResizeMode mode)

将调整页眉大小的限制设置为给定的mode 所描述的限制。

另请参阅 sectionResizeMode()、length() 和sectionResized()。

void QHeaderView::setSectionResizeMode(int logicalIndex, QHeaderView::ResizeMode mode)

将页眉中logicalIndex 指定的部分的大小调整限制设置为给定的mode 所描述的限制。调用此函数时,逻辑索引应已存在。

注意: 如果stretchLastSection 属性设置为 true,则最后一节的设置将被忽略。这是QTreeView 提供的水平标题的默认设置。

另请参阅 setStretchLastSection() 和resizeContentsPrecision()。

void QHeaderView::setSectionsClickable(bool clickable)

sectionsClickable 设置为clickable

注: 属性sectionsClickable 的设置函数。

另请参见 sectionsClickable().

void QHeaderView::setSectionsMovable(bool movable)

sectionsMovable 设置为movable

注: 属性sectionsMovable 的设置函数。

另请参阅 sectionsMovable() 。

[override virtual protected] void QHeaderView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags)

重实现:QAbstractItemView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags)。

根据指定的flags 选择给定rect 中的项目。

基类实现不做任何操作。

void QHeaderView::setSortIndicator(int logicalIndex, Qt::SortOrder order)

order 指定的方向设置logicalIndex 指定的部分的排序指示符,并删除任何其他部分的排序指示符。

logicalIndex 可以是-1,在这种情况下,将不显示排序指示符,模型将返回其自然的、未排序的顺序。请注意,并非所有模型都支持这种排序,在这种情况下甚至可能会崩溃。

另请参阅 sortIndicatorSection() 和sortIndicatorOrder()。

[override virtual] void QHeaderView::setVisible(bool v)

重构属性访问函数:QWidget::visible

void QHeaderView::showSection(int logicalIndex)

显示logicalIndex 指定的部分。

另请参阅 hideSection()、isSectionHidden()、hiddenSectionCount() 和setSectionHidden() 。

[override virtual] QSize QHeaderView::sizeHint() const

重实现:QAbstractScrollArea::sizeHint() 常量。

返回该标头的合适尺寸提示。

另请参阅 sectionSizeHint().

[signal] void QHeaderView::sortIndicatorChanged(int logicalIndex, Qt::SortOrder order)

当包含排序指示符的部分或指示的顺序发生变化时,就会发出该信号。该部分的逻辑索引由logicalIndex 指定,排序顺序由order 指定。

另请参阅 setSortIndicator() 。

Qt::SortOrder QHeaderView::sortIndicatorOrder() const

返回排序指示器的顺序。如果没有章节有排序指示符,则此函数的返回值未定义。

另请参阅 setSortIndicator() 和sortIndicatorSection()。

int QHeaderView::sortIndicatorSection() const

返回有排序指示符的部分的逻辑索引。默认为第 0 部分。

另请参阅 setSortIndicator()、sortIndicatorOrder() 和setSortIndicatorShown()。

int QHeaderView::stretchSectionCount() const

返回设置为调整大小模式拉伸的部分的数量。在视图中,当视图的几何形状发生变化时,可以用它来查看标题视图是否需要调整各部分的大小。

另请参阅 stretchLastSection

void QHeaderView::swapSections(int first, int second)

将位于视觉索引first 的部分与位于视觉索引second 的部分互换。

另请参见 moveSection().

[override virtual protected] int QHeaderView::verticalOffset() const

重实现:QAbstractItemView::verticalOffset() 常量。

返回页眉的垂直偏移量。水平标题的偏移量为 0。

另请参阅 offset().

[override virtual protected] bool QHeaderView::viewportEvent(QEvent *e)

重实现:QAbstractItemView::viewportEvent(QEvent *event).

int QHeaderView::visualIndex(int logicalIndex) const

返回logicalIndex 指定部分的视觉索引位置,否则返回-1。

隐藏部分的视觉索引仍然有效。

另请参阅 logicalIndex() 。

int QHeaderView::visualIndexAt(int position) const

返回视口中覆盖给定position 的部分的视觉索引。

另请参阅 logicalIndexAt()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.