QTreeView 类

QTreeView 类为树视图提供默认模型/视图实现。 更多...

头: #include <QTreeView>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QAbstractItemView
继承者:

QHelpContentWidget and QTreeWidget

特性

公共函数

QTreeView (QWidget * parent = nullptr)
virtual ~QTreeView ()
bool allColumnsShowFocus () const
int autoExpandDelay () const
int columnAt (int x ) const
int columnViewportPosition (int column ) const
int columnWidth (int column ) const
bool expandsOnDoubleClick () const
QHeaderView * header () const
int indentation () const
QModelIndex indexAbove (const QModelIndex & index ) const
QModelIndex indexBelow (const QModelIndex & index ) const
bool isAnimated () const
bool isColumnHidden (int column ) const
bool isExpanded (const QModelIndex & index ) const
bool isFirstColumnSpanned (int row , const QModelIndex & parent ) const
bool isHeaderHidden () const
bool isRowHidden (int row , const QModelIndex & parent ) const
bool isSortingEnabled () const
bool itemsExpandable () const
void resetIndentation ()
bool rootIsDecorated () const
void setAllColumnsShowFocus (bool enable )
void setAnimated (bool enable )
void setAutoExpandDelay (int delay )
void setColumnHidden (int column , bool hide )
void setColumnWidth (int column , int width )
void setExpanded (const QModelIndex & index , bool expanded )
void setExpandsOnDoubleClick (bool enable )
void setFirstColumnSpanned (int row , const QModelIndex & parent , bool span )
void setHeader (QHeaderView * header )
void setHeaderHidden (bool hide )
void setIndentation (int i )
void setItemsExpandable (bool enable )
void setRootIsDecorated (bool show )
void setRowHidden (int row , const QModelIndex & parent , bool hide )
void setSortingEnabled (bool enable )
void setTreePosition (int index )
void setUniformRowHeights (bool uniform )
void setWordWrap (bool on )
int treePosition () const
bool uniformRowHeights () const
bool wordWrap () const

重实现公共函数

virtual void dataChanged (const QModelIndex & topLeft , const QModelIndex & bottomRight , const QList<int> & roles = QList<int>()) override
virtual QModelIndex indexAt (const QPoint & point ) const override
virtual void keyboardSearch (const QString & search ) override
virtual void reset () override
virtual void scrollTo (const QModelIndex & index , QAbstractItemView::ScrollHint hint = EnsureVisible) override
virtual void selectAll () override
virtual void setModel (QAbstractItemModel * model ) override
virtual void setRootIndex (const QModelIndex & index ) override
virtual void setSelectionModel (QItemSelectionModel * selectionModel ) override
virtual QRect visualRect (const QModelIndex & index ) const override

公共槽

void collapse (const QModelIndex & index )
void collapseAll ()
void expand (const QModelIndex & index )
void expandAll ()
void expandRecursively (const QModelIndex & index , int depth = -1)
void expandToDepth (int depth )
void hideColumn (int column )
void resizeColumnToContents (int column )
void showColumn (int column )
void sortByColumn (int column , Qt::SortOrder order )

信号

void collapsed (const QModelIndex & index )
void expanded (const QModelIndex & index )

保护函数

virtual void drawBranches (QPainter * painter , const QRect & rect , const QModelIndex & index ) const
virtual void drawRow (QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const
void drawTree (QPainter * painter , const QRegion & region ) const
int indexRowSizeHint (const QModelIndex & index ) const
int rowHeight (const QModelIndex & index ) const

重实现保护函数

virtual void changeEvent (QEvent * event ) override
virtual void currentChanged (const QModelIndex & current , const QModelIndex & 上一 ) override
virtual void dragMoveEvent (QDragMoveEvent * event ) override
virtual int horizontalOffset () const override
virtual bool isIndexHidden (const QModelIndex & index ) const override
virtual void keyPressEvent (QKeyEvent * event ) override
virtual void mouseDoubleClickEvent (QMouseEvent * event ) override
virtual void mouseMoveEvent (QMouseEvent * event ) override
virtual void mousePressEvent (QMouseEvent * event ) override
virtual void mouseReleaseEvent (QMouseEvent * event ) override
virtual QModelIndex moveCursor (QAbstractItemView::CursorAction cursorAction , Qt::KeyboardModifiers modifiers ) override
virtual void paintEvent (QPaintEvent * event ) override
virtual void rowsAboutToBeRemoved (const QModelIndex & parent , int start , int end ) override
virtual void rowsInserted (const QModelIndex & parent , int start , int end ) override
virtual void scrollContentsBy (int dx , int dy ) override
virtual QModelIndexList selectedIndexes () const override
virtual void selectionChanged (const QItemSelection & selected , const QItemSelection & deselected ) override
virtual void setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags 命令 ) override
virtual int sizeHintForColumn (int column ) const override
virtual void timerEvent (QTimerEvent * event ) override
virtual void updateGeometries () override
virtual int verticalOffset () const override
virtual bool viewportEvent (QEvent * event ) override
virtual QSize viewportSizeHint () const override
virtual QRegion visualRegionForSelection (const QItemSelection & selection ) const override

保护槽

void columnCountChanged (int oldCount , int newCount )
void columnMoved ()
void columnResized (int column , int oldSize , int newSize )
void rowsRemoved (const QModelIndex & parent , int start , int end )

详细描述

QTreeView 实现来自模型的项的树表示。此类用于提供标准分层列表,先前提供是通过 QListView 类,但使用由 Qt 模型/视图体系结构提供的方式更灵活。

QTreeView 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .

QTreeView 实现的接口定义通过 QAbstractItemView 类以允许它显示提供数据,通过模型派生自 QAbstractItemModel 类。

构建树视图以显示来自模型的数据很简单。在以下范例中,目录内容的提供通过 QFileSystemModel 并作为树显示:

    QFileSystemModel *model = new QFileSystemModel;
    model->setRootPath(QDir::currentPath());
    QTreeView *tree = new QTreeView(splitter);
    tree->setModel(model);
					

模型/视图体系结构确保树视图内容随模型改变更新。

拥有子级的项可以处于展开 (子级可见) 或折叠 (隐藏子级) 状态。当此状态改变 collapsed () 或 expanded () 信号被发射带有相关项模型索引。

用于指示层次结构级别缩进量的控制通过 indentation 特性。

树视图 Header (头部) 的构造是使用 QHeaderView 类且可以被隐藏使用 header()->hide() 。注意,每个 Header (头部) 的配置采用其 stretchLastSection 特性被设为 true,确保视图不浪费为 Header (头部) 赋值的任何空间。若此值被设为 true,此特性将覆盖 Header (头部) 最后区间设置的重置大小模式。

默认情况下,树视图的所有列是可移动的,除第一列外。要禁用这些列的移动,使用 QHeaderView 's setSectionsMovable () function. For more information about rearranging sections, see 移动 Header (头部) 区间 .

键绑定

QTreeView 支持使用户能够在视图中导航并与项内容交互的一组键绑定:

Key 动作
Up 将光标移至上一行相同列项。若当前项父级没有更多行可导航,光标将移至父级之前最后同级行相关项。
Down 将光标移至下一行相同项列。若当前项父级没有更多行可导航,光标将移至紧随父级的第一同级行相关项。
Left 通过折叠分支,隐藏当前项的子级 (若存在)。
Minus 如同 Left。
Right 通过展开分支,展现当前项的子级 (若存在)。
Plus 如同 Right。
星号 展开当前项及其所有子级 (若存在)。
PageUp 上移光标一页。
PageDown 下移光标一页。
Home 将光标移至模型中第一顶层项第一行同一列项。
End 将光标移至模型中最后顶层项最后行同一列项。
F2 对于可编辑模型,这打开当前项以供编辑。Escape 键可以用于取消编辑过程,并恢复显示数据的任何改变。

改善性能

给出正处理数据的有关视图提示,以提高其性能是可能的,当显示大量项时。对于打算显示等高项的视图,可以接受的一种方式是设置 uniformRowHeights 特性为 true。

另请参阅 QListView , QTreeWidget , 视图类 , QAbstractItemModel ,和 QAbstractItemView .

特性文档编制

allColumnsShowFocus : bool

此特性保持项是否应使用所有列展示键盘聚焦

若此特性为 true 所有列将展示焦点,否则仅一列将展示焦点。

默认为 false。

访问函数:

bool allColumnsShowFocus () const
void setAllColumnsShowFocus (bool enable )

animated : bool

此特性保持是否启用动画

若此特性为 true 树视图将动画分支的扩展和折叠。若此特性为 false ,树视图将立即展开 (或折叠) 分支 (不展示动画)。

默认情况下,此特性为 false .

访问函数:

bool isAnimated () const
void setAnimated (bool enable )

autoExpandDelay : int

此特性保持延迟时间,在拖放操作期间打开树项之前。

此特性保持以毫秒为单位的时间量,在该节点自动打开 (或关闭) 之前用户必须在节点上等待。若将时间设为小于 0,则不激活。

默认情况下,此特性拥有 -1 值,意味着禁用自动展开。

访问函数:

int autoExpandDelay () const
void setAutoExpandDelay (int delay )

expandsOnDoubleClick : bool

此特性保持是否可以通过双击展开项。

此特性保持用户是否可以通过双击展开和折叠项。默认值为 true。

访问函数:

bool expandsOnDoubleClick () const
void setExpandsOnDoubleClick (bool enable )

另请参阅 itemsExpandable .

headerHidden : bool

此特性保持是否展示 Header (头)。

若此特性为 true ,不展示 Header (头),否则展示。默认值为 false。

访问函数:

bool isHeaderHidden () const
void setHeaderHidden (bool hide )

另请参阅 header ().

indentation : int

树视图中项的缩进。

此特性保持树视图每级项的缩进度量 (以像素为单位)。对于顶层项,缩进指定从视口边缘到第一列项的水平距离;对于子级项,从父级项指定其缩进。

默认情况下,此特性的值从属样式。因此,当样式改变时,此特性随之更新。调用 setIndentation() 停止更新,调用 resetIndentation() 将还原默认行为。

访问函数:

int indentation () const
void setIndentation (int i )
void resetIndentation ()

itemsExpandable : bool

此特性保持项是否可以由用户展开。

此特性保持用户是否可以交互展开和折叠项。

默认情况下,此特性为 true .

访问函数:

bool itemsExpandable () const
void setItemsExpandable (bool enable )

rootIsDecorated : bool

此特性保持是否展示用于展开和折叠顶层项的控件

通常,采用控件展示具有子级的项的展开和折叠,允许展示 (或隐藏) 它们的子级。若此特性为 false,顶层项不展示这些控件。这可以用于使单级树结构,外观像简单项列表。

默认情况下,此特性为 true .

访问函数:

bool rootIsDecorated () const
void setRootIsDecorated (bool show )

sortingEnabled : bool

此特性保持是否启用排序

若此特性为 true ,树启用排序;若特性为 false,不启用排序。默认值为 false。

注意: 为避免性能问题,推荐启用排序 after 将项插入树中。另外,也可以将项插入列表,在将项插入树之前。

访问函数:

bool isSortingEnabled () const
void setSortingEnabled (bool enable )

另请参阅 sortByColumn ().

uniformRowHeights : bool

此特性保持树视图中的所有项是否拥有相同高度

This property should only be set to true if it is guaranteed that all items in the view has the same height. This enables the view to do some optimizations.

The height is obtained from the first item in the view. It is updated when the data changes on that item.

注意: If the editor size hint is bigger than the cell size hint, then the size hint of the editor will be used.

默认情况下,此特性为 false .

访问函数:

bool uniformRowHeights () const
void setUniformRowHeights (bool uniform )

wordWrap : bool

此特性保持项文本的自动换行策略

若此特性为 true 那么有必要在单词分割处换行项文本;否则,根本不换行。此特性为 false 在默认情况下。

Note that even if wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current textElideMode .

访问函数:

bool wordWrap () const
void setWordWrap (bool on )

成员函数文档编制

[explicit] QTreeView:: QTreeView ( QWidget * parent = nullptr)

构造树视图采用 parent 来表示模型数据。使用 setModel () 来设置模型。

另请参阅 QAbstractItemModel .

[virtual noexcept] QTreeView:: ~QTreeView ()

销毁树视图。

[override virtual protected] void QTreeView:: changeEvent ( QEvent * event )

重实现: QFrame::changeEvent (QEvent *ev).

[slot] void QTreeView:: collapse (const QModelIndex & index )

折叠的模型项指定通过 index .

另请参阅 collapsed ().

[slot] void QTreeView:: collapseAll ()

折叠所有展开项。

另请参阅 expandAll (), expand (), collapse (),和 setExpanded ().

[signal] void QTreeView:: collapsed (const QModelIndex & index )

此信号被发射当项指定通过 index is collapsed.

int QTreeView:: columnAt ( int x ) const

Returns the column in the tree view whose header covers the x coordinate given.

[protected slot] void QTreeView:: columnCountChanged ( int oldCount , int newCount )

Informs the tree view that the number of columns in the tree view has changed from oldCount to newCount .

[protected slot] void QTreeView:: columnMoved ()

This slot is called whenever a column has been moved.

[protected slot] void QTreeView:: columnResized ( int column , int oldSize , int newSize )

This function is called whenever column 's size is changed in the header. oldSize and newSize give the previous size and the new size in pixels.

另请参阅 setColumnWidth ().

int QTreeView:: columnViewportPosition ( int column ) const

Returns the horizontal position of the column in the viewport.

int QTreeView:: columnWidth ( int column ) const

返回宽度为 column .

另请参阅 resizeColumnToContents () 和 setColumnWidth ().

[override virtual protected] void QTreeView:: currentChanged (const QModelIndex & current , const QModelIndex & 上一 )

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

[override virtual] void QTreeView:: dataChanged (const QModelIndex & topLeft , const QModelIndex & bottomRight , const QList < int > & roles = QList<int>())

重实现: QAbstractItemView::dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles).

[override virtual protected] void QTreeView:: dragMoveEvent ( QDragMoveEvent * event )

重实现: QAbstractItemView::dragMoveEvent (QDragMoveEvent *event).

[virtual protected] void QTreeView:: drawBranches ( QPainter * painter , const QRect & rect , const QModelIndex & index ) const

Draws the branches in the tree view on the same row as the model item index ,使用 painter given. The branches are drawn in the rectangle specified by rect .

[virtual protected] void QTreeView:: drawRow ( QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const

Draws the row in the tree view that contains the model item index ,使用 painter given. The option controls how the item is displayed.

另请参阅 setAlternatingRowColors ().

[protected] void QTreeView:: drawTree ( QPainter * painter , const QRegion & region ) const

Draws the part of the tree intersecting the given region 使用指定 painter .

另请参阅 paintEvent ().

[slot] void QTreeView:: expand (const QModelIndex & index )

Expands the model item specified by the index .

另请参阅 expanded ().

[slot] void QTreeView:: expandAll ()

展开所有可展开项。

注意: This function will not try to fetch more data.

警告: If the model contains a large number of items, this function will take some time to execute.

另请参阅 collapseAll (), expand (), collapse (),和 setExpanded ().

[slot] void QTreeView:: expandRecursively (const QModelIndex & index , int depth = -1)

Expands the item at the given index and all its children to the given depth depth is relative to the given index depth of -1 will expand all children, a depth of 0 will only expand the given index .

注意: This function will not try to fetch more data.

警告: If the model contains a large number of items, this function will take some time to execute.

另请参阅 expandAll ().

[slot] void QTreeView:: expandToDepth ( int depth )

展开所有可展开项到给定 depth .

注意: This function will not try to fetch more data.

另请参阅 expandAll (), collapseAll (), expand (), collapse (),和 setExpanded ().

[signal] void QTreeView:: expanded (const QModelIndex & index )

此信号被发射当项指定通过 index is expanded.

另请参阅 setExpanded ().

返回用于树视图的 Header (头)。

另请参阅 setHeader () 和 QAbstractItemModel::headerData ().

[slot] void QTreeView:: hideColumn ( int column )

隐藏 column 给定。

注意: This function should only be called after the model has been initialized, as the view needs to know the number of columns in order to hide column .

另请参阅 showColumn () 和 setColumnHidden ().

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

重实现: QAbstractItemView::horizontalOffset() const .

Returns the horizontal offset of the items in the treeview.

Note that the tree view uses the horizontal header section positions to determine the positions of columns in the view.

另请参阅 verticalOffset ().

QModelIndex QTreeView:: indexAbove (const QModelIndex & index ) const

Returns the model index of the item above index .

[override virtual] QModelIndex QTreeView:: indexAt (const QPoint & point ) const

重实现: QAbstractItemView::indexAt(const QPoint &point) const .

QModelIndex QTreeView:: indexBelow (const QModelIndex & index ) const

Returns the model index of the item below index .

[protected] int QTreeView:: indexRowSizeHint (const QModelIndex & index ) const

Returns the size hint for the row indicated by index .

另请参阅 sizeHintForColumn () 和 uniformRowHeights ().

bool QTreeView:: isColumnHidden ( int column ) const

返回 true column 被隐藏;否则返回 false .

另请参阅 hideColumn () 和 isRowHidden ().

bool QTreeView:: isExpanded (const QModelIndex & index ) const

返回 true 若模型项 index 被展开;否则返回 false。

另请参阅 expand (), expanded (),和 setExpanded ().

bool QTreeView:: isFirstColumnSpanned ( int row , const QModelIndex & parent ) const

返回 true 若第一列中的项在给定 row parent 跨越所有列;否则返回 false .

另请参阅 setFirstColumnSpanned ().

[override virtual protected] bool QTreeView:: isIndexHidden (const QModelIndex & index ) const

重实现: QAbstractItemView::isIndexHidden(const QModelIndex &index) const .

bool QTreeView:: isRowHidden ( int row , const QModelIndex & parent ) const

返回 true 若项在给定 row parent 被隐藏;否则返回 false .

另请参阅 setRowHidden () 和 isColumnHidden ().

[override virtual protected] void QTreeView:: keyPressEvent ( QKeyEvent * event )

重实现: QAbstractItemView::keyPressEvent (QKeyEvent *event).

[override virtual] void QTreeView:: keyboardSearch (const QString & search )

重实现: QAbstractItemView::keyboardSearch (const QString &search).

[override virtual protected] void QTreeView:: mouseDoubleClickEvent ( QMouseEvent * event )

重实现: QAbstractItemView::mouseDoubleClickEvent (QMouseEvent *event).

[override virtual protected] void QTreeView:: mouseMoveEvent ( QMouseEvent * event )

重实现: QAbstractItemView::mouseMoveEvent (QMouseEvent *event).

[override virtual protected] void QTreeView:: mousePressEvent ( QMouseEvent * event )

重实现: QAbstractItemView::mousePressEvent (QMouseEvent *event).

[override virtual protected] void QTreeView:: mouseReleaseEvent ( QMouseEvent * event )

重实现: QAbstractItemView::mouseReleaseEvent (QMouseEvent *event).

[override virtual protected] QModelIndex QTreeView:: moveCursor ( QAbstractItemView::CursorAction cursorAction , Qt::KeyboardModifiers modifiers )

重实现: QAbstractItemView::moveCursor (QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers).

Move the cursor in the way described by cursorAction , using the information provided by the button modifiers .

[override virtual protected] void QTreeView:: paintEvent ( QPaintEvent * event )

重实现: QAbstractScrollArea::paintEvent (QPaintEvent *event).

[override virtual] void QTreeView:: reset ()

重实现: QAbstractItemView::reset ().

[slot] void QTreeView:: resizeColumnToContents ( int column )

重置大小 column given to the size of its contents.

另请参阅 columnWidth (), setColumnWidth (), sizeHintForColumn (),和 QHeaderView::resizeContentsPrecision ().

[protected] int QTreeView:: rowHeight (const QModelIndex & index ) const

返回指示行的高度通过给定 index .

另请参阅 indexRowSizeHint ().

[override virtual protected] void QTreeView:: rowsAboutToBeRemoved (const QModelIndex & parent , int start , int end )

重实现: QAbstractItemView::rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end).

Informs the view that the rows from the start row to the end row inclusive are about to removed from the given parent model item.

[override virtual protected] void QTreeView:: rowsInserted (const QModelIndex & parent , int start , int end )

重实现: QAbstractItemView::rowsInserted (const QModelIndex &parent, int start, int end).

Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item.

[protected slot] void QTreeView:: rowsRemoved (const QModelIndex & parent , int start , int end )

Informs the view that the rows from the start row to the end row inclusive have been removed from the given parent model item.

[override virtual protected] void QTreeView:: scrollContentsBy ( int dx , int dy )

重实现: QAbstractScrollArea::scrollContentsBy (int dx, int dy).

卷动树视图内容通过 ( dx , dy ).

[override virtual] void QTreeView:: scrollTo (const QModelIndex & index , QAbstractItemView::ScrollHint hint = EnsureVisible)

重实现: QAbstractItemView::scrollTo (const QModelIndex &index, QAbstractItemView::ScrollHint hint).

Scroll the contents of the tree view until the given model item index 可见。 hint parameter specifies more precisely where the item should be located after the operation. If any of the parents of the model item are collapsed, they will be expanded to ensure that the model item is visible.

[override virtual] void QTreeView:: selectAll ()

重实现: QAbstractItemView::selectAll ().

[override virtual protected] QModelIndexList QTreeView:: selectedIndexes () const

重实现: QAbstractItemView::selectedIndexes() const .

[override virtual protected] void QTreeView:: selectionChanged (const QItemSelection & selected , const QItemSelection & deselected )

重实现: QAbstractItemView::selectionChanged (const QItemSelection &selected, const QItemSelection &deselected).

void QTreeView:: setColumnHidden ( int column , bool hide )

hide 为 true column 被隐藏,否则 column 被展示。

另请参阅 isColumnHidden (), hideColumn (),和 setRowHidden ().

void QTreeView:: setColumnWidth ( int column , int width )

设置宽度为给定 column width 指定。

另请参阅 columnWidth () 和 resizeColumnToContents ().

void QTreeView:: setExpanded (const QModelIndex & index , bool expanded )

Sets the item referred to by index to either collapse or expanded, depending on the value of expanded .

另请参阅 expanded (), expand (),和 isExpanded ().

void QTreeView:: setFirstColumnSpanned ( int row , const QModelIndex & parent , bool span )

span is true the item in the first column in the row 采用给定 parent is set to span all columns, otherwise all items on the row are shown.

另请参阅 isFirstColumnSpanned ().

void QTreeView:: setHeader ( QHeaderView * header )

Sets the header for the tree view, to the given header .

The view takes ownership over the given header and deletes it when a new header is set.

另请参阅 QAbstractItemModel::headerData ().

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

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

[override virtual] void QTreeView:: setRootIndex (const QModelIndex & index )

重实现: QAbstractItemView::setRootIndex (const QModelIndex &index).

void QTreeView:: setRowHidden ( int row , const QModelIndex & parent , bool hide )

hide 为 true row 采用给定 parent 被隐藏,否则 row 被展示。

另请参阅 isRowHidden () 和 setColumnHidden ().

[override virtual protected] void QTreeView:: setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags 命令 )

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

应用选定 命令 到矩形内项,或触及的通过矩形 rect .

另请参阅 selectionCommand ().

[override virtual] void QTreeView:: setSelectionModel ( QItemSelectionModel * selectionModel )

重实现: QAbstractItemView::setSelectionModel (QItemSelectionModel *selectionModel).

void QTreeView:: setTreePosition ( int index )

这指定树结构应放置在逻辑索引 index 。若 设为 -1 则树始终紧跟视觉索引 0。

另请参阅 treePosition (), QHeaderView::swapSections (),和 QHeaderView::moveSection ().

[slot] void QTreeView:: showColumn ( int column )

展示给定 column 在树视图。

另请参阅 hideColumn () 和 setColumnHidden ().

[override virtual protected] int QTreeView:: sizeHintForColumn ( int column ) const

重实现: QAbstractItemView::sizeHintForColumn(int column) const .

返回大小提示为 column 的宽度或 -1 若没有模型。

若需要将给定列宽度设为固定值,调用 QHeaderView::resizeSection () 在视图的 Header (头部)。

If you reimplement this function in a subclass, note that the value you return is only used when resizeColumnToContents () is called. In that case, if a larger column width is required by either the view's header or the item delegate, that width will be used instead.

另请参阅 QWidget::sizeHint , header (),和 QHeaderView::resizeContentsPrecision ().

[slot] void QTreeView:: sortByColumn ( int column , Qt::SortOrder order )

Sorts the model by the values in the given column and order .

column 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.

另请参阅 sortingEnabled .

[override virtual protected] void QTreeView:: timerEvent ( QTimerEvent * event )

重实现: QAbstractItemView::timerEvent (QTimerEvent *event).

int QTreeView:: treePosition () const

Return the logical index the tree is set on. If the return value is -1 then the tree is placed on the visual index 0.

另请参阅 setTreePosition ().

[override virtual protected] void QTreeView:: updateGeometries ()

重实现: QAbstractItemView::updateGeometries ().

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

重实现: QAbstractItemView::verticalOffset() const .

返回树视图中项的垂直偏移。

另请参阅 horizontalOffset ().

[override virtual protected] bool QTreeView:: viewportEvent ( QEvent * event )

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

[override virtual protected] QSize QTreeView:: viewportSizeHint () const

重实现: QAbstractItemView::viewportSizeHint() const .

[override virtual] QRect QTreeView:: visualRect (const QModelIndex & index ) const

重实现: QAbstractItemView::visualRect(const QModelIndex &index) const .

返回项所占据的视口矩形为 index 。若索引不可见或被明确隐藏,返回矩形无效。

[override virtual protected] QRegion QTreeView:: visualRegionForSelection (const QItemSelection & selection ) const

重实现: QAbstractItemView::visualRegionForSelection(const QItemSelection &selection) const .

返回矩形从项视口在给定 selection .

从 4.7 起,返回区域仅包含 (或包括在) 视口相交矩形。