Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QTreeView Class Reference

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

    #include <QTreeView>

Inherits QAbstractItemView.

Inherited by QTreeWidget.

- List of all members, including inherited members

### Writable Properties

- indentation : int
- rootIsDecorated : bool

- 7 writable properties inherited from QAbstractItemView
- 2 writable properties inherited from QViewport
- 5 writable properties inherited from QFrame
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- 1 read-only property inherited from QViewport
- 1 read-only property inherited from QFrame
- 24 read-only properties inherited from QWidget

### Public Functions

- QTreeView ( QWidget * parent = 0 )
- ~QTreeView ()
- int columnAt ( int x ) const
- int columnViewportPosition ( int column ) const
- int columnWidth ( int column ) const
- virtual void doItemsLayout ()
- virtual void ensureItemVisible ( const QModelIndex & index )
- QHeaderView * header () const
- bool isColumnHidden ( int column ) const
- bool isOpen ( const QModelIndex & index ) const
- bool isRowHidden ( int row, const QModelIndex & parent ) const
- QModelIndex itemAbove ( const QModelIndex & index ) const
- virtual QModelIndex itemAt ( int x, int y ) const
- QModelIndex itemBelow ( const QModelIndex & index ) const
- virtual QRect itemViewportRect ( const QModelIndex & index ) const
- void setColumnHidden ( int column, bool hide )
- void setHeader ( QHeaderView * header )
- void setRowHidden ( int row, const QModelIndex & parent, bool hide )

- 22 public functions inherited from QAbstractItemView
- 4 public functions inherited from QViewport
- 2 public functions inherited from QFrame
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- void close ( const QModelIndex & index )
- void hideColumn ( int column )
- void open ( const QModelIndex & index )
- void resizeColumnToContents ( int column )
- virtual void selectAll ()
- void showColumn ( int column )

- 6 public slots inherited from QAbstractItemView
- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

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

- 9 signals inherited from QAbstractItemView
- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- virtual int columnSizeHint ( int column ) const
- virtual void drawBranches ( QPainter * painter, const QRect & rect, const QModelIndex & index ) const
- virtual void drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
- virtual int horizontalOffset () const
- virtual QModelIndex moveCursor ( QAbstractItemView::CursorAction cursorAction, Qt::ButtonState state )
- int rowSizeHint ( const QModelIndex & left ) const
- virtual void rowsInserted ( const QModelIndex & parent, int start, int end )
- virtual void rowsRemoved ( const QModelIndex & parent, int start, int end )
- virtual void scrollContentsBy ( int dx, int dy )
- virtual QRect selectionViewportRect ( const QItemSelection & selection ) const
- virtual void setSelection ( const QRect & rect, QItemSelectionModel::SelectionFlags command )
- virtual int verticalOffset () const

- 33 protected functions inherited from QAbstractItemView
- 17 protected functions inherited from QViewport
- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

### Protected Slots

- void columnCountChanged ( int oldCount, int newCount )
- void columnIndexesChanged ()
- void columnWidthChanged ( int column, int oldSize, int newSize )

- 8 protected slots inherited from QAbstractItemView

## Detailed Description

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

A QTreeView implements a tree representation of items from a model. This class is used to provide standard hierarchical lists that were previously provided by the `QListView` class, but using the more flexible approach provided by Qt's model/view architecture.

QTreeView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.

It is simple to construct a tree view displaying data from a model. In the following example, the contents of a directory are supplied by a QDirModel and displayed as a tree:

        QDirModel *model = new QDirModel(QDir(), parent);
        QTreeView *tree = new QTreeView(parent);
        tree->setModel(model);

The model/view architecture ensures that the contents of the tree view are updated as the model changes.

Items that have children can be in an expanded (children are visible) or collapsed (children are hidden) state. When this state changes a collapsed() or expanded() signal is emitted with the model index of the relevant item.

The amount of indentation used to indicate levels of hierarchy is controlled by the indentation property.

See also Model/View Programming, QAbstractItemModel, and QAbstractItemView.

## Property Documentation

### indentation : int

This property holds indentation of the items in the tree view.

This property holds the indentation of the items for each level in the tree view.

Access functions:

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

See also setIndentation().

### rootIsDecorated : bool

This property holds whether to show controls for opening and closing items.

This property holds whether root items are displayed with controls for opening and closing them.

Access functions:

- bool rootIsDecorated () const
- void setRootIsDecorated ( bool show )

## Member Function Documentation

### QTreeView::QTreeView ( QWidget * parent = 0 )

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

See also QAbstractItemModel.

### QTreeView::~QTreeView ()

Destroys the tree view.

### void QTreeView::close ( const QModelIndex & index ) `[slot]`

Closes the model item specified by the index.

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

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.

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

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

### void QTreeView::columnIndexesChanged () `[protected slot]`

This slot is called whenever the items in the tree view are changed.

### int QTreeView::columnSizeHint ( int column ) const `[virtual protected]`

Returns the size hint for the column's width.

Reimplemented from QAbstractItemView.

See also QWidget::sizeHint.

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

### void QTreeView::columnWidthChanged ( int column, int oldSize, int newSize ) `[protected slot]`

Changes the column's width from the size specified by oldSize to the size specified by newSize.

### void QTreeView::doItemsLayout () `[virtual]`

Lays out the items in the tree view.

Reimplemented from QAbstractItemView.

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

Draws the branches in the tree view on the same row as the model item index, using the painter given. Only the branches within the rectangle specified by rect are drawn.

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

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

See also QStyleOptionViewItem.

### void QTreeView::ensureItemVisible ( const QModelIndex & index ) `[virtual]`

Scroll the contents of the tree view until the given model item index is visible.

Reimplemented from QAbstractItemView.

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

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

### QHeaderView * QTreeView::header () const

Returns the header for the tree view.

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

Hides the column given.

See also showColumn().

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

Returns the horizontal offset.

Reimplemented from QAbstractItemView.

### bool QTreeView::isColumnHidden ( int column ) const

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

See also hideColumn().

### bool QTreeView::isOpen ( const QModelIndex & index ) const

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

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

See also setRowHidden().

### QModelIndex QTreeView::itemAbove ( const QModelIndex & index ) const

Returns the model index of the item above index.

### QModelIndex QTreeView::itemAt ( int x, int y ) const `[virtual]`

Returns the model index of the item at point (x, y).

Reimplemented from QAbstractItemView.

### QModelIndex QTreeView::itemBelow ( const QModelIndex & index ) const

Returns the model index of the item below index.

### QRect QTreeView::itemViewportRect ( const QModelIndex & index ) const `[virtual]`

Returns the rectangle on the viewport occupied by the item at index.

Reimplemented from QAbstractItemView.

### QModelIndex QTreeView::moveCursor ( QAbstractItemView::CursorAction cursorAction, Qt::ButtonState state ) `[virtual protected]`

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

Reimplemented from QAbstractItemView.

See also QAbstractItemView::CursorAction.

### void QTreeView::open ( const QModelIndex & index ) `[slot]`

Opens the model item specified by the index.

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

Resizes the column given to the size of its contents.

### int QTreeView::rowSizeHint ( const QModelIndex & left ) const `[protected]`

Returns the size hint for the column's width.

See also QWidget::sizeHint.

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

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

Reimplemented from QAbstractItemView.

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

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

Reimplemented from QAbstractItemView.

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

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

Reimplemented from QViewport.

### void QTreeView::selectAll () `[virtual slot]`

Selects all the items in the underlying model.

Reimplemented from QAbstractItemView.

### QRect QTreeView::selectionViewportRect ( const QItemSelection & selection ) const `[virtual protected]`

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

Reimplemented from QAbstractItemView.

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

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

### void QTreeView::setHeader ( QHeaderView * header )

Sets the header for the tree view.

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

See also isRowHidden().

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

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

Reimplemented from QAbstractItemView.

See also selectionCommand().

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

Shows the given column in the tree view.

See also hideColumn().

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

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

Reimplemented from QAbstractItemView.