QTreeView Class

The QTreeView class provides a default model/view implementation of a tree view. 更多...

头文件: #include <QTreeView>
qmake: QT += widgets
基类: QAbstractItemView
派生类:

QTreeWidget

属性

公有函数

QTreeView(QWidget *parent = Q_NULLPTR)
~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)
void sortByColumn(int column, Qt::SortOrder order)
int treePosition() const
bool uniformRowHeights() const
bool wordWrap() const

重新实现的公有函数

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

公有槽函数

void collapse(const QModelIndex &index)
void collapseAll()
void expand(const QModelIndex &index)
void expandAll()
void expandToDepth(int depth)
void hideColumn(int column)
void resizeColumnToContents(int column)
void showColumn(int column)

信号

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 currentChanged(const QModelIndex &current, const QModelIndex &previous)
virtual void dragMoveEvent(QDragMoveEvent *event)
virtual int horizontalOffset() const
virtual bool isIndexHidden(const QModelIndex &index) const
virtual void keyPressEvent(QKeyEvent *event)
virtual void mouseDoubleClickEvent(QMouseEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
virtual void paintEvent(QPaintEvent *event)
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
virtual void scrollContentsBy(int dx, int dy)
virtual QModelIndexList selectedIndexes() const
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
virtual int sizeHintForColumn(int column) const
virtual void timerEvent(QTimerEvent *event)
virtual void updateGeometries()
virtual int verticalOffset() const
virtual bool viewportEvent(QEvent *event)
virtual QSize viewportSizeHint() const
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const

Protected Slots

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)

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

The QTreeView class provides a default model/view implementation of a tree view.

QTreeView 为模型中的项提供树状显示, 提供标准的分层列表.

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

QTreeView 派生自 QAbstractItemView , 并实现其定义的接口, 可以显示从 QAbstractItemModel 派生的模型类提供的数据.

你很容易构造一个显示模型数据的树状视图. 如下所示的QTreeView, 目录内容由 QFileSystemModel提供:


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

模型/视图体系结构确保树视图的内容随着模型的变化而更新.

具有子项的项可以处于展开(子项可见)或折叠(子项隐藏)状态. 折叠状态发生变化时, 会发出 collapsed() 或 expanded() 信号, 其中包含相关项的模型索引.

层次级别的缩进量由 indentation 属性控制.

树视图中的标题使用 QHeaderView 类构造, 并且可以使用 header()->hide()隐藏. 注意, 每个标题都可以将属性 stretchLastSection 设置为true, 确保视图不会浪费为其标头分配的任何空间. 如果这个属性设置为true, 则这个属性将覆盖在页眉最后一节上设置的调整大小模式.

默认情况下, 树视图中除第一列外的所有列都是可移动的. 调用 QHeaderView's setSectionsMovable() 函数禁用列的移动. 有关重新排列节的详细信息, 参见 Moving Header Sections.

Key Bindings

QTreeView 支持一组键盘绑定:

KeyAction
UpMoves the cursor to the item in the same column on the previous row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the last row of the sibling that precedes the parent.
DownMoves the cursor to the item in the same column on the next row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the first row of the sibling that follows the parent.
LeftHides the children of the current item (if present) by collapsing a branch.
MinusSame as LeftArrow.
RightReveals the children of the current item (if present) by expanding a branch.
PlusSame as RightArrow.
AsteriskExpands all children of the current item (if present).
PageUpMoves the cursor up one page.
PageDownMoves the cursor down one page.
HomeMoves the cursor to an item in the same column of the first row of the first top-level item in the model.
EndMoves the cursor to an item in the same column of the last row of the last top-level item in the model.
F2In editable models, this opens the current item for editing. The Escape key can be used to cancel the editing process and revert any changes to the data displayed.
Screenshot of a Windows Vista style tree viewScreenshot of a Macintosh style tree viewScreenshot of a Fusion style tree view
A Windows Vista style tree view.A Macintosh style tree view.A Fusion style tree view.

Improving Performance

在显示大量项时, 你可以在视图上显示正在处理的数据, 以提高性能. 视图显示高度相等的项时, 可以采取的一种方法是将 uniformRowHeights 属性设置为true.

参见 QListView, QTreeWidget, View Classes, QAbstractItemModel, QAbstractItemView, and Dir View Example.

属性

allColumnsShowFocus : bool

This property holds whether items should show keyboard focus using all columns

If this property is true all columns will show focus, otherwise only one column will show focus.

The default is false.

This property was introduced in Qt 4.2.

访问函数:

bool allColumnsShowFocus() const
void setAllColumnsShowFocus(bool enable)

animated : bool

This property holds whether animations are enabled

If this property is true the treeview will animate expansion and collapsing of branches. If this property is false, the treeview will expand or collapse branches immediately without showing the animation.

By default, this property is false.

This property was introduced in Qt 4.2.

访问函数:

bool isAnimated() const
void setAnimated(bool enable)

autoExpandDelay : int

This property holds the delay time before items in a tree are opened during a drag and drop operation.

This property holds the amount of time in milliseconds that the user must wait over a node before that node will automatically open or close. If the time is set to less then 0 then it will not be activated.

By default, this property has a value of -1, meaning that auto-expansion is disabled.

This property was introduced in Qt 4.3.

访问函数:

int autoExpandDelay() const
void setAutoExpandDelay(int delay)

expandsOnDoubleClick : bool

This property holds whether the items can be expanded by double-clicking.

This property holds whether the user can expand and collapse items by double-clicking. The default value is true.

This property was introduced in Qt 4.4.

访问函数:

bool expandsOnDoubleClick() const
void setExpandsOnDoubleClick(bool enable)

参见 itemsExpandable.

headerHidden : bool

This property holds whether the header is shown or not.

If this property is true, the header is not shown otherwise it is. The default value is false.

This property was introduced in Qt 4.4.

访问函数:

bool isHeaderHidden() const
void setHeaderHidden(bool hide)

参见 header().

indentation : int

indentation of the items in the tree view.

This property holds the indentation measured in pixels of the items for each level in the tree view. For top-level items, the indentation specifies the horizontal distance from the viewport edge to the items in the first column; for child items, it specifies their indentation from their parent items.

By default, the value of this property is style dependent. Thus, when the style changes, this property updates from it. Calling setIndentation() stops the updates, calling resetIndentation() will restore default behavior.

访问函数:

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

itemsExpandable : bool

This property holds whether the items are expandable by the user.

This property holds whether the user can expand and collapse items interactively.

By default, this property is true.

访问函数:

bool itemsExpandable() const
void setItemsExpandable(bool enable)

rootIsDecorated : bool

This property holds whether to show controls for expanding and collapsing top-level items

Items with children are typically shown with controls to expand and collapse them, allowing their children to be shown or hidden. If this property is false, these controls are not shown for top-level items. This can be used to make a single level tree structure appear like a simple list of items.

By default, this property is true.

访问函数:

bool rootIsDecorated() const
void setRootIsDecorated(bool show)

sortingEnabled : bool

This property holds whether sorting is enabled

If this property is true, sorting is enabled for the tree; if the property is false, sorting is not enabled. The default value is false.

Note: In order to avoid performance issues, it is recommended that sorting is enabled after inserting the items into the tree. Alternatively, you could also insert the items into a list before inserting the items into the tree.

This property was introduced in Qt 4.2.

访问函数:

bool isSortingEnabled() const
void setSortingEnabled(bool enable)

参见 sortByColumn().

uniformRowHeights : bool

This property holds whether all items in the treeview have the same height

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.

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

By default, this property is false.

访问函数:

bool uniformRowHeights() const
void setUniformRowHeights(bool uniform)

wordWrap : bool

This property holds the item text word-wrapping policy

If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is false by default.

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.

This property was introduced in Qt 4.3.

访问函数:

bool wordWrap() const
void setWordWrap(bool on)

成员函数

QTreeView::QTreeView(QWidget *parent = Q_NULLPTR)

Constructs a tree view with a parent to represent a model's data. Use setModel() to set the model.

参见 QAbstractItemModel.

QTreeView::~QTreeView()

Destroys the tree view.

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

Collapses the model item specified by the index.

参见 collapsed().

[slot] void QTreeView::collapseAll()

Collapses all expanded items.

This function was introduced in Qt 4.2.

参见 expandAll(), expand(), collapse(), and setExpanded().

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

This signal is emitted when the item specified by 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

Returns the width of the column.

参见 resizeColumnToContents() and setColumnWidth().

[virtual protected] void QTreeView::currentChanged(const QModelIndex &current, const QModelIndex &previous)

重新实现 QAbstractItemView::currentChanged().

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

重新实现 QAbstractItemView::dataChanged().

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

重新实现 QWidget::dragMoveEvent().

[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, using the 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, using the 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 using the specified painter.

This function was introduced in Qt 4.2.

参见 paintEvent().

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

Expands the model item specified by the index.

参见 expanded().

[slot] void QTreeView::expandAll()

Expands all expandable items.

Warning: if the model contains a large number of items, this function will take some time to execute.

This function was introduced in Qt 4.2.

参见 collapseAll(), expand(), collapse(), and setExpanded().

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

Expands all expandable items to the given depth.

This function was introduced in Qt 4.3.

参见 expandAll(), collapseAll(), expand(), collapse(), and setExpanded().

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

This signal is emitted when the item specified by index is expanded.

参见 setExpanded().

Returns the header for the tree view.

参见 setHeader() and QAbstractItemModel::headerData().

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

Hides the column given.

Note: 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() and setColumnHidden().

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

重新实现 QAbstractItemView::horizontalOffset().

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.

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

重新实现 QAbstractItemView::indexAt().

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() and uniformRowHeights().

bool QTreeView::isColumnHidden(int column) const

Returns true if the column is hidden; otherwise returns false.

参见 hideColumn() and isRowHidden().

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

Returns true if the model item index is expanded; otherwise returns false.

参见 expand(), expanded(), and setExpanded().

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

Returns true if the item in first column in the given row of the parent is spanning all the columns; otherwise returns false.

This function was introduced in Qt 4.3.

参见 setFirstColumnSpanned().

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

重新实现 QAbstractItemView::isIndexHidden().

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

Returns true if the item in the given row of the parent is hidden; otherwise returns false.

参见 setRowHidden() and isColumnHidden().

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

重新实现 QWidget::keyPressEvent().

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

重新实现 QAbstractItemView::keyboardSearch().

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

重新实现 QWidget::mouseDoubleClickEvent().

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

重新实现 QWidget::mouseMoveEvent().

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

重新实现 QWidget::mousePressEvent().

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

重新实现 QWidget::mouseReleaseEvent().

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

重新实现 QAbstractItemView::moveCursor().

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

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

重新实现 QWidget::paintEvent().

[virtual] void QTreeView::reset()

重新实现 QAbstractItemView::reset().

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

Resizes the column given to the size of its contents.

参见 columnWidth(), setColumnWidth(), sizeHintForColumn(), and QHeaderView::resizeContentsPrecision().

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

Returns the height of the row indicated by the given index.

This function was introduced in Qt 4.3.

参见 indexRowSizeHint().

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

重新实现 QAbstractItemView::rowsAboutToBeRemoved().

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.

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

重新实现 QAbstractItemView::rowsInserted().

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.

This function was introduced in Qt 4.1.

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

重新实现 QAbstractScrollArea::scrollContentsBy().

Scrolls the contents of the tree view by (dx, dy).

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

重新实现 QAbstractItemView::scrollTo().

Scroll the contents of the tree view until the given model item index is visible. The 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.

[virtual] void QTreeView::selectAll()

重新实现 QAbstractItemView::selectAll().

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

重新实现 QAbstractItemView::selectedIndexes().

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

重新实现 QAbstractItemView::selectionChanged().

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

If hide is true the column is hidden, otherwise the column is shown.

参见 isColumnHidden(), hideColumn(), and setRowHidden().

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

Sets the width of the given column to the width specified.

This function was introduced in Qt 4.2.

参见 columnWidth() and 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(), and isExpanded().

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

If span is true the item in the first column in the row with the given parent is set to span all columns, otherwise all items on the row are shown.

This function was introduced in Qt 4.3.

参见 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().

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

重新实现 QAbstractItemView::setModel().

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

重新实现 QAbstractItemView::setRootIndex().

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

If hide is true the row with the given parent is hidden, otherwise the row is shown.

参见 isRowHidden() and setColumnHidden().

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

重新实现 QAbstractItemView::setSelection().

Applies the selection command to the items in or touched by the rectangle, rect.

参见 selectionCommand().

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

重新实现 QAbstractItemView::setSelectionModel().

void QTreeView::setTreePosition(int index)

This specifies that the tree structure should be placed at logical index index. If set to -1 then the tree will always follow visual index 0.

This function was introduced in Qt 5.2.

参见 treePosition(), QHeaderView::swapSections(), and QHeaderView::moveSection().

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

Shows the given column in the tree view.

参见 hideColumn() and setColumnHidden().

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

重新实现 QAbstractItemView::sizeHintForColumn().

Returns the size hint for the column's width or -1 if there is no model.

If you need to set the width of a given column to a fixed value, call QHeaderView::resizeSection() on the view's 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(), and QHeaderView::resizeContentsPrecision().

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

Sets the model up for sorting 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.

This function was introduced in Qt 4.2.

参见 sortingEnabled.

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

重新实现 QObject::timerEvent().

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.

This function was introduced in Qt 5.2.

参见 setTreePosition().

[virtual protected] void QTreeView::updateGeometries()

重新实现 QAbstractItemView::updateGeometries().

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

重新实现 QAbstractItemView::verticalOffset().

Returns the vertical offset of the items in the tree view.

参见 horizontalOffset().

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

重新实现 QAbstractScrollArea::viewportEvent().

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

重新实现 QAbstractScrollArea::viewportSizeHint().

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

重新实现 QAbstractItemView::visualRect().

Returns the rectangle on the viewport occupied by the item at index. If the index is not visible or explicitly hidden, the returned rectangle is invalid.

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

重新实现 QAbstractItemView::visualRegionForSelection().

Returns the rectangle from the viewport of the items in the given selection.

Since 4.7, the returned region only contains rectangles intersecting (or included in) the viewport.