QtBase  v6.3.1
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Properties | Friends | List of all members
QTreeView Class Reference

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

#include <qtreeview.h>

Inheritance diagram for QTreeView:
Inheritance graph
[legend]
Collaboration diagram for QTreeView:
Collaboration graph
[legend]

Public Slots

void hideColumn (int column)
 
void showColumn (int column)
 
void expand (const QModelIndex &index)
 
void collapse (const QModelIndex &index)
 
void resizeColumnToContents (int column)
 
void sortByColumn (int column, Qt::SortOrder order)
 
void expandAll ()
 
void expandRecursively (const QModelIndex &index, int depth=-1)
 
void collapseAll ()
 
void expandToDepth (int depth)
 
- Public Slots inherited from QAbstractItemView
void edit (const QModelIndex &index)
 
void clearSelection ()
 
void setCurrentIndex (const QModelIndex &index)
 
void scrollToTop ()
 
void scrollToBottom ()
 
void update (const QModelIndex &index)
 

Signals

void expanded (const QModelIndex &index)
 
void collapsed (const QModelIndex &index)
 
- Signals inherited from QAbstractItemView
void pressed (const QModelIndex &index)
 
void clicked (const QModelIndex &index)
 
void doubleClicked (const QModelIndex &index)
 
void activated (const QModelIndex &index)
 
void entered (const QModelIndex &index)
 
void viewportEntered ()
 
void iconSizeChanged (const QSize &size)
 

Public Member Functions

 QTreeView (QWidget *parent=nullptr)
 
 ~QTreeView ()
 
void setModel (QAbstractItemModel *model) override
 
void setRootIndex (const QModelIndex &index) override
 
void setSelectionModel (QItemSelectionModel *selectionModel) override
 
QHeaderViewheader () const
 
void setHeader (QHeaderView *header)
 
int autoExpandDelay () const
 
void setAutoExpandDelay (int delay)
 
int indentation () const
 
void setIndentation (int i)
 
void resetIndentation ()
 
bool rootIsDecorated () const
 
void setRootIsDecorated (bool show)
 
bool uniformRowHeights () const
 
void setUniformRowHeights (bool uniform)
 
bool itemsExpandable () const
 
void setItemsExpandable (bool enable)
 
bool expandsOnDoubleClick () const
 
void setExpandsOnDoubleClick (bool enable)
 
int columnViewportPosition (int column) const
 
int columnWidth (int column) const
 
void setColumnWidth (int column, int width)
 
int columnAt (int x) const
 
bool isColumnHidden (int column) const
 
void setColumnHidden (int column, bool hide)
 
bool isHeaderHidden () const
 
void setHeaderHidden (bool hide)
 
bool isRowHidden (int row, const QModelIndex &parent) const
 
void setRowHidden (int row, const QModelIndex &parent, bool hide)
 
bool isFirstColumnSpanned (int row, const QModelIndex &parent) const
 
void setFirstColumnSpanned (int row, const QModelIndex &parent, bool span)
 
bool isExpanded (const QModelIndex &index) const
 
void setExpanded (const QModelIndex &index, bool expand)
 
void setSortingEnabled (bool enable)
 
bool isSortingEnabled () const
 
void setAnimated (bool enable)
 
bool isAnimated () const
 
void setAllColumnsShowFocus (bool enable)
 
bool allColumnsShowFocus () const
 
void setWordWrap (bool on)
 
bool wordWrap () const
 
void setTreePosition (int logicalIndex)
 
int treePosition () const
 
void keyboardSearch (const QString &search) override
 
QRect visualRect (const QModelIndex &index) const override
 
void scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible) override
 
QModelIndex indexAt (const QPoint &p) const override
 
QModelIndex indexAbove (const QModelIndex &index) const
 
QModelIndex indexBelow (const QModelIndex &index) const
 
void doItemsLayout () override
 
void reset () override
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >()) override
 
void selectAll () override
 
- Public Member Functions inherited from QAbstractItemView
 QAbstractItemView (QWidget *parent=nullptr)
 
 ~QAbstractItemView ()
 
QAbstractItemModelmodel () const
 
QItemSelectionModelselectionModel () const
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 
QAbstractItemDelegateitemDelegate () const
 
void setSelectionMode (QAbstractItemView::SelectionMode mode)
 
QAbstractItemView::SelectionMode selectionMode () const
 
void setSelectionBehavior (QAbstractItemView::SelectionBehavior behavior)
 
QAbstractItemView::SelectionBehavior selectionBehavior () const
 
QModelIndex currentIndex () const
 
QModelIndex rootIndex () const
 
void setEditTriggers (EditTriggers triggers)
 
EditTriggers editTriggers () const
 
void setVerticalScrollMode (ScrollMode mode)
 
ScrollMode verticalScrollMode () const
 
void resetVerticalScrollMode ()
 
void setHorizontalScrollMode (ScrollMode mode)
 
ScrollMode horizontalScrollMode () const
 
void resetHorizontalScrollMode ()
 
void setAutoScroll (bool enable)
 
bool hasAutoScroll () const
 
void setAutoScrollMargin (int margin)
 
int autoScrollMargin () const
 
void setTabKeyNavigation (bool enable)
 
bool tabKeyNavigation () const
 
void setAlternatingRowColors (bool enable)
 
bool alternatingRowColors () const
 
void setIconSize (const QSize &size)
 
QSize iconSize () const
 
void setTextElideMode (Qt::TextElideMode mode)
 
Qt::TextElideMode textElideMode () const
 
QSize sizeHintForIndex (const QModelIndex &index) const
 
virtual int sizeHintForRow (int row) const
 
void openPersistentEditor (const QModelIndex &index)
 
void closePersistentEditor (const QModelIndex &index)
 
bool isPersistentEditorOpen (const QModelIndex &index) const
 
void setIndexWidget (const QModelIndex &index, QWidget *widget)
 
QWidgetindexWidget (const QModelIndex &index) const
 
void setItemDelegateForRow (int row, QAbstractItemDelegate *delegate)
 
QAbstractItemDelegateitemDelegateForRow (int row) const
 
void setItemDelegateForColumn (int column, QAbstractItemDelegate *delegate)
 
QAbstractItemDelegateitemDelegateForColumn (int column) const
 
virtual QAbstractItemDelegateitemDelegateForIndex (const QModelIndex &index) const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 

Protected Slots

void columnResized (int column, int oldSize, int newSize)
 
void columnCountChanged (int oldCount, int newCount)
 
void columnMoved ()
 
void reexpand ()
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
void verticalScrollbarValueChanged (int value) override
 
- Protected Slots inherited from QAbstractItemView
virtual void updateEditorData ()
 
virtual void updateEditorGeometries ()
 
virtual void verticalScrollbarAction (int action)
 
virtual void verticalScrollbarValueChanged (int value)
 
virtual void horizontalScrollbarValueChanged (int value)
 
virtual void closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
 
virtual void commitData (QWidget *editor)
 
virtual void editorDestroyed (QObject *editor)
 

Protected Member Functions

 QTreeView (QTreeViewPrivate &dd, QWidget *parent=nullptr)
 
void scrollContentsBy (int dx, int dy) override
 
void rowsInserted (const QModelIndex &parent, int start, int end) override
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end) override
 
QModelIndex moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override
 
int horizontalOffset () const override
 
int verticalOffset () const override
 
void setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command) override
 
QRegion visualRegionForSelection (const QItemSelection &selection) const override
 
QModelIndexList selectedIndexes () const override
 
void changeEvent (QEvent *event) override
 
void timerEvent (QTimerEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void drawTree (QPainter *painter, const QRegion &region) const
 
virtual void drawRow (QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
 
virtual void drawBranches (QPainter *painter, const QRect &rect, const QModelIndex &index) const
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
bool viewportEvent (QEvent *event) override
 
void updateGeometries () override
 
QSize viewportSizeHint () const override
 
int sizeHintForColumn (int column) const override
 
int indexRowSizeHint (const QModelIndex &index) const
 
int rowHeight (const QModelIndex &index) const
 
void horizontalScrollbarAction (int action) override
 
bool isIndexHidden (const QModelIndex &index) const override
 
void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected) override
 
void currentChanged (const QModelIndex &current, const QModelIndex &previous) override
 
- Protected Member Functions inherited from QAbstractItemView
 QAbstractItemView (QAbstractItemViewPrivate &, QWidget *parent=nullptr)
 
virtual bool edit (const QModelIndex &index, EditTrigger trigger, QEvent *event)
 
virtual QItemSelectionModel::SelectionFlags selectionCommand (const QModelIndex &index, const QEvent *event=nullptr) const
 
virtual void initViewItemOption (QStyleOptionViewItem *option) const
 
State state () const
 
void setState (State state)
 
void scheduleDelayedItemsLayout ()
 
void executeDelayedItemsLayout ()
 
void setDirtyRegion (const QRegion &region)
 
void scrollDirtyRegion (int dx, int dy)
 
QPoint dirtyRegionOffset () const
 
void startAutoScroll ()
 
void stopAutoScroll ()
 
void doAutoScroll ()
 
bool focusNextPrevChild (bool next) override
 
bool event (QEvent *event) override
 
bool viewportEvent (QEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void focusInEvent (QFocusEvent *event) override
 
void focusOutEvent (QFocusEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void timerEvent (QTimerEvent *event) override
 
void inputMethodEvent (QInputMethodEvent *event) override
 
bool eventFilter (QObject *object, QEvent *event) override
 
QSize viewportSizeHint () const override
 

Properties

int autoExpandDelay
 The delay time before items in a tree are opened during a drag and drop operation. More...
 
int indentation
 indentation of the items in the tree view. More...
 
bool rootIsDecorated
 whether to show controls for expanding and collapsing top-level items More...
 
bool uniformRowHeights
 whether all items in the treeview have the same height More...
 
bool itemsExpandable
 whether the items are expandable by the user. More...
 
bool sortingEnabled
 whether sorting is enabled More...
 
bool animated
 whether animations are enabled More...
 
bool allColumnsShowFocus
 whether items should show keyboard focus using all columns More...
 
bool wordWrap
 the item text word-wrapping policy More...
 
bool headerHidden
 whether the header is shown or not. More...
 
bool expandsOnDoubleClick
 whether the items can be expanded by double-clicking. More...
 
- Properties inherited from QAbstractItemView
bool autoScroll
 whether autoscrolling in drag move events is enabled More...
 
int autoScrollMargin
 the size of the area when auto scrolling is triggered More...
 
EditTriggers editTriggers
 which actions will initiate item editing More...
 
bool tabKeyNavigation
 whether item navigation with tab and backtab is enabled. More...
 
bool alternatingRowColors
 whether to draw the background using alternating colors More...
 
SelectionMode selectionMode
 which selection mode the view operates in More...
 
SelectionBehavior selectionBehavior
 which selection behavior the view uses More...
 
QSize iconSize
 the size of items' icons More...
 
Qt::TextElideMode textElideMode
 the position of the "..." in elided text. More...
 
ScrollMode verticalScrollMode
 how the view scrolls its contents in the vertical direction More...
 
ScrollMode horizontalScrollMode
 how the view scrolls its contents in the horizontal direction More...
 

Friends

class ::tst_QTreeView
 
class QAccessibleTable
 
class QAccessibleTree
 
class QAccessibleTableCell
 

Additional Inherited Members

- Public Types inherited from QAbstractItemView
enum  SelectionMode {
  NoSelection , SingleSelection , MultiSelection , ExtendedSelection ,
  ContiguousSelection
}
 
enum  SelectionBehavior { SelectItems , SelectRows , SelectColumns }
 
enum  ScrollHint { EnsureVisible , PositionAtTop , PositionAtBottom , PositionAtCenter }
 
enum  EditTrigger {
  NoEditTriggers = 0 , CurrentChanged = 1 , DoubleClicked = 2 , SelectedClicked = 4 ,
  EditKeyPressed = 8 , AnyKeyPressed = 16 , AllEditTriggers = 31
}
 
enum  ScrollMode { ScrollPerItem , ScrollPerPixel }
 
- Protected Types inherited from QAbstractItemView
enum  CursorAction {
  MoveUp , MoveDown , MoveLeft , MoveRight ,
  MoveHome , MoveEnd , MovePageUp , MovePageDown ,
  MoveNext , MovePrevious
}
 
enum  State {
  NoState , DraggingState , DragSelectingState , EditingState ,
  ExpandingState , CollapsingState , AnimatingState
}
 

Detailed Description

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

\inmodule QtWidgets

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.

The QTreeView class is one of the \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{model/view framework}.

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 QFileSystemModel and displayed as a tree:

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 \l indentation property.

Headers in tree views are constructed using the QHeaderView class and can be hidden using {header()->hide()}. Note that each header is configured with its \l{QHeaderView::}{stretchLastSection} property set to true, ensuring that the view does not waste any of the space assigned to it for its header. If this value is set to true, this property will override the resize mode set on the last section in the header.

By default, all columns in a tree view are movable except the first. To disable movement of these columns, use QHeaderView's \l {QHeaderView::}{setSectionsMovable()} function. For more information about rearranging sections, see \l {Moving Header Sections}.

Definition at line 55 of file qtreeview.h.

Constructor & Destructor Documentation

◆ QTreeView() [1/2]

QTreeView::QTreeView ( QWidget parent = nullptr)
explicit

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

See also
QAbstractItemModel

Definition at line 187 of file qtreeview.cpp.

◆ ~QTreeView()

QTreeView::~QTreeView ( )

Destroys the tree view.

Definition at line 207 of file qtreeview.cpp.

◆ QTreeView() [2/2]

QTreeView::QTreeView ( QTreeViewPrivate dd,
QWidget parent = nullptr 
)
protected

Definition at line 197 of file qtreeview.cpp.

Member Function Documentation

◆ allColumnsShowFocus()

bool QTreeView::allColumnsShowFocus ( ) const

Definition at line 939 of file qtreeview.cpp.

◆ autoExpandDelay()

int QTreeView::autoExpandDelay ( ) const

Definition at line 352 of file qtreeview.cpp.

◆ changeEvent()

void QTreeView::changeEvent ( QEvent event)
overrideprotected

\reimp

Definition at line 1243 of file qtreeview.cpp.

◆ collapse

void QTreeView::collapse ( const QModelIndex index)
slot

Collapses the model item specified by the index.

See also
collapsed()

Definition at line 797 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ collapseAll

void QTreeView::collapseAll ( )
slot
Since
4.2

Collapses all expanded items.

See also
expandAll(), expand(), collapse(), setExpanded()

Definition at line 2762 of file qtreeview.cpp.

Here is the call graph for this function:

◆ collapsed

void QTreeView::collapsed ( const QModelIndex index)
signal

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

Here is the caller graph for this function:

◆ columnAt()

int QTreeView::columnAt ( int  x) const

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

Definition at line 537 of file qtreeview.cpp.

◆ columnCountChanged

void QTreeView::columnCountChanged ( int  oldCount,
int  newCount 
)
protectedslot

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

Definition at line 2589 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ columnMoved

void QTreeView::columnMoved ( )
protectedslot

This slot is called whenever a column has been moved.

Definition at line 2506 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ columnResized

void QTreeView::columnResized ( int  column,
int  oldSize,
int  newSize 
)
protectedslot

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.

See also
setColumnWidth()

Definition at line 2838 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ columnViewportPosition()

int QTreeView::columnViewportPosition ( int  column) const

Returns the horizontal position of the column in the viewport.

Definition at line 503 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ columnWidth()

int QTreeView::columnWidth ( int  column) const

Returns the width of the column.

See also
resizeColumnToContents(), setColumnWidth()

Definition at line 514 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ currentChanged()

void QTreeView::currentChanged ( const QModelIndex current,
const QModelIndex previous 
)
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 4013 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dataChanged()

void QTreeView::dataChanged ( const QModelIndex topLeft,
const QModelIndex bottomRight,
const QList< int > &  roles = QList<int>() 
)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Reimplemented in TreeView, and QTreeWidgetDataChanged.

Definition at line 677 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doItemsLayout()

void QTreeView::doItemsLayout ( )
overridevirtual

Reimplemented from QAbstractItemView.

Definition at line 2115 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawBranches()

void QTreeView::drawBranches ( QPainter painter,
const QRect rect,
const QModelIndex index 
) const
protectedvirtual

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.

Definition at line 1840 of file qtreeview.cpp.

Here is the call graph for this function:

◆ drawRow()

void QTreeView::drawRow ( QPainter painter,
const QStyleOptionViewItem &  option,
const QModelIndex index 
) const
protectedvirtual

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.

See also
setAlternatingRowColors()

Definition at line 1645 of file qtreeview.cpp.

Here is the call graph for this function:

◆ drawTree()

void QTreeView::drawTree ( QPainter painter,
const QRegion region 
) const
protected
Since
4.2 Draws the part of the tree intersecting the given region using the specified painter.
See also
paintEvent()

Definition at line 1486 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expand

void QTreeView::expand ( const QModelIndex index)
slot

Expands the model item specified by the index.

See also
expanded()

Definition at line 762 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expandAll

void QTreeView::expandAll ( )
slot
Since
4.2 Expands all expandable items.
Note
This function will not try to \l{QAbstractItemModel::fetchMore}{fetch more} data.
Warning
If the model contains a large number of items, this function will take some time to execute.
See also
collapseAll(), expand(), collapse(), setExpanded()

Definition at line 2698 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expanded

void QTreeView::expanded ( const QModelIndex index)
signal

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

Here is the caller graph for this function:

◆ expandRecursively

void QTreeView::expandRecursively ( const QModelIndex index,
int  depth = -1 
)
slot
Since
5.13 Expands the item at the given index and all its children to the given depth. The depth is relative to the given index. A depth of -1 will expand all children, a depth of 0 will only expand the given index.
Note
This function will not try to \l{QAbstractItemModel::fetchMore}{fetch more} data.
Warning
If the model contains a large number of items, this function will take some time to execute.
See also
expandAll()

Definition at line 2723 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expandsOnDoubleClick()

bool QTreeView::expandsOnDoubleClick ( ) const

Definition at line 488 of file qtreeview.cpp.

◆ expandToDepth

void QTreeView::expandToDepth ( int  depth)
slot
Since
4.3 Expands all expandable items to the given depth.
Note
This function will not try to \l{QAbstractItemModel::fetchMore}{fetch more} data.
See also
expandAll(), collapseAll(), expand(), collapse(), setExpanded()

Definition at line 2788 of file qtreeview.cpp.

Here is the call graph for this function:

◆ header()

QHeaderView * QTreeView::header ( ) const

Returns the header for the tree view.

See also
QAbstractItemModel::headerData()

Definition at line 295 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ hideColumn

void QTreeView::hideColumn ( int  column)
slot

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.
See also
showColumn(), setColumnHidden()

Definition at line 732 of file qtreeview.cpp.

Here is the call graph for this function:

◆ horizontalOffset()

int QTreeView::horizontalOffset ( ) const
overrideprotectedvirtual

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.

See also
verticalOffset()

Implements QAbstractItemView.

Definition at line 2166 of file qtreeview.cpp.

◆ horizontalScrollbarAction()

void QTreeView::horizontalScrollbarAction ( int  action)
overrideprotectedvirtual

Reimplemented from QAbstractItemView.

Definition at line 3055 of file qtreeview.cpp.

Here is the call graph for this function:

◆ indentation()

int QTreeView::indentation ( ) const

Definition at line 377 of file qtreeview.cpp.

◆ indexAbove()

QModelIndex QTreeView::indexAbove ( const QModelIndex index) const

Returns the model index of the item above index.

Definition at line 2081 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexAt()

QModelIndex QTreeView::indexAt ( const QPoint point) const
overridevirtual

\reimp

Implements QAbstractItemView.

Definition at line 2057 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexBelow()

QModelIndex QTreeView::indexBelow ( const QModelIndex index) const

Returns the model index of the item below index.

Definition at line 2097 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ indexRowSizeHint()

int QTreeView::indexRowSizeHint ( const QModelIndex index) const
protected

Returns the size hint for the row indicated by index.

See also
sizeHintForColumn(), uniformRowHeights()

Definition at line 2974 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isAnimated()

bool QTreeView::isAnimated ( ) const

Definition at line 913 of file qtreeview.cpp.

◆ isColumnHidden()

bool QTreeView::isColumnHidden ( int  column) const

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

See also
hideColumn(), isRowHidden()

Definition at line 548 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ isExpanded()

bool QTreeView::isExpanded ( const QModelIndex index) const

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

See also
expand(), expanded(), setExpanded()

Definition at line 834 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ isFirstColumnSpanned()

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

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

See also
setFirstColumnSpanned()

Definition at line 634 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ isHeaderHidden()

bool QTreeView::isHeaderHidden ( ) const

Definition at line 577 of file qtreeview.cpp.

◆ isIndexHidden()

bool QTreeView::isIndexHidden ( const QModelIndex index) const
overrideprotectedvirtual

\reimp

Implements QAbstractItemView.

Definition at line 3063 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRowHidden()

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(), isColumnHidden()

Definition at line 595 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ isSortingEnabled()

bool QTreeView::isSortingEnabled ( ) const

Definition at line 888 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ itemsExpandable()

bool QTreeView::itemsExpandable ( ) const

Definition at line 466 of file qtreeview.cpp.

◆ keyboardSearch()

void QTreeView::keyboardSearch ( const QString search)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 1007 of file qtreeview.cpp.

Here is the call graph for this function:

◆ keyPressEvent()

void QTreeView::keyPressEvent ( QKeyEvent event)
overrideprotected

\reimp

Definition at line 2032 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseDoubleClickEvent()

void QTreeView::mouseDoubleClickEvent ( QMouseEvent event)
overrideprotected

\reimp

Definition at line 1963 of file qtreeview.cpp.

Here is the call graph for this function:

◆ mouseMoveEvent()

void QTreeView::mouseMoveEvent ( QMouseEvent event)
overrideprotected

\reimp

Definition at line 2022 of file qtreeview.cpp.

Here is the call graph for this function:

◆ mousePressEvent()

void QTreeView::mousePressEvent ( QMouseEvent event)
overrideprotected

\reimp

Definition at line 1932 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseReleaseEvent()

void QTreeView::mouseReleaseEvent ( QMouseEvent event)
overrideprotected

\reimp

Definition at line 1947 of file qtreeview.cpp.

Here is the call graph for this function:

◆ moveCursor()

QModelIndex QTreeView::moveCursor ( CursorAction  cursorAction,
Qt::KeyboardModifiers  modifiers 
)
overrideprotectedvirtual

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

Implements QAbstractItemView.

Definition at line 2201 of file qtreeview.cpp.

Here is the call graph for this function:

◆ paintEvent()

void QTreeView::paintEvent ( QPaintEvent event)
overrideprotected

\reimp

Definition at line 1337 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reexpand

void QTreeView::reexpand ( )
protectedslot

Definition at line 2516 of file qtreeview.cpp.

◆ reset()

void QTreeView::reset ( )
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 2148 of file qtreeview.cpp.

Here is the call graph for this function:

◆ resetIndentation()

void QTreeView::resetIndentation ( )

Definition at line 393 of file qtreeview.cpp.

◆ resizeColumnToContents

void QTreeView::resizeColumnToContents ( int  column)
slot

Resizes the column given to the size of its contents.

See also
columnWidth(), setColumnWidth(), sizeHintForColumn(), QHeaderView::resizeContentsPrecision()

Definition at line 2607 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rootIsDecorated()

bool QTreeView::rootIsDecorated ( ) const

Definition at line 413 of file qtreeview.cpp.

◆ rowHeight()

int QTreeView::rowHeight ( const QModelIndex index) const
protected
Since
4.3 Returns the height of the row indicated by the given index.
See also
indexRowSizeHint()

Definition at line 3042 of file qtreeview.cpp.

◆ rowsAboutToBeRemoved()

void QTreeView::rowsAboutToBeRemoved ( const QModelIndex parent,
int  start,
int  end 
)
overrideprotectedvirtual

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.

Reimplemented from QAbstractItemView.

Definition at line 2563 of file qtreeview.cpp.

Here is the call graph for this function:

◆ rowsInserted()

void QTreeView::rowsInserted ( const QModelIndex parent,
int  start,
int  end 
)
overrideprotectedvirtual

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.

Definition at line 2525 of file qtreeview.cpp.

Here is the call graph for this function:

◆ rowsRemoved

void QTreeView::rowsRemoved ( const QModelIndex parent,
int  start,
int  end 
)
protectedslot
Since
4.1

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

Definition at line 2576 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ scrollContentsBy()

void QTreeView::scrollContentsBy ( int  dx,
int  dy 
)
overrideprotected

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

Definition at line 2451 of file qtreeview.cpp.

Here is the call graph for this function:

◆ scrollTo()

void QTreeView::scrollTo ( const QModelIndex index,
ScrollHint  hint = EnsureVisible 
)
overridevirtual

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.

Implements QAbstractItemView.

Definition at line 1144 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ selectAll()

void QTreeView::selectAll ( )
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 2645 of file qtreeview.cpp.

Here is the call graph for this function:

◆ selectedIndexes()

QModelIndexList QTreeView::selectedIndexes ( ) const
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 2430 of file qtreeview.cpp.

Here is the call graph for this function:

◆ selectionChanged()

void QTreeView::selectionChanged ( const QItemSelection selected,
const QItemSelection deselected 
)
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 4045 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAllColumnsShowFocus()

void QTreeView::setAllColumnsShowFocus ( bool  enable)

Definition at line 930 of file qtreeview.cpp.

◆ setAnimated()

void QTreeView::setAnimated ( bool  enable)

Definition at line 907 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setAutoExpandDelay()

void QTreeView::setAutoExpandDelay ( int  delay)

Definition at line 358 of file qtreeview.cpp.

◆ setColumnHidden()

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

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

See also
hideColumn(), setRowHidden()

Definition at line 559 of file qtreeview.cpp.

Here is the call graph for this function:

◆ setColumnWidth()

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

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

See also
columnWidth(), resizeColumnToContents()

Definition at line 527 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setExpanded()

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.

See also
expanded(), expand(), isExpanded()

Definition at line 846 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setExpandsOnDoubleClick()

void QTreeView::setExpandsOnDoubleClick ( bool  enable)

Definition at line 494 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setFirstColumnSpanned()

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

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.

See also
isFirstColumnSpanned()

Definition at line 652 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setHeader()

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.

See also
QAbstractItemModel::headerData()

Definition at line 309 of file qtreeview.cpp.

Here is the call graph for this function:

◆ setHeaderHidden()

void QTreeView::setHeaderHidden ( bool  hide)

Definition at line 583 of file qtreeview.cpp.

Here is the call graph for this function:

◆ setIndentation()

void QTreeView::setIndentation ( int  i)

Definition at line 383 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setItemsExpandable()

void QTreeView::setItemsExpandable ( bool  enable)

Definition at line 472 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setModel()

void QTreeView::setModel ( QAbstractItemModel model)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 214 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRootIndex()

void QTreeView::setRootIndex ( const QModelIndex index)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 260 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRootIsDecorated()

void QTreeView::setRootIsDecorated ( bool  show)

Definition at line 419 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRowHidden()

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(), setColumnHidden()

Definition at line 608 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSelection()

void QTreeView::setSelection ( const QRect rect,
QItemSelectionModel::SelectionFlags  command 
)
overrideprotectedvirtual

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

See also
selectionCommand()

Implements QAbstractItemView.

Definition at line 2334 of file qtreeview.cpp.

Here is the call graph for this function:

◆ setSelectionModel()

void QTreeView::setSelectionModel ( QItemSelectionModel selectionModel)
overridevirtual

\reimp

Reimplemented from QAbstractItemView.

Reimplemented in QTreeWidget.

Definition at line 270 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSortingEnabled()

void QTreeView::setSortingEnabled ( bool  enable)

Definition at line 870 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTreePosition()

void QTreeView::setTreePosition ( int  index)
Since
5.2

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

See also
treePosition(), QHeaderView::swapSections(), QHeaderView::moveSection()

Definition at line 982 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setUniformRowHeights()

void QTreeView::setUniformRowHeights ( bool  uniform)

Definition at line 450 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ setWordWrap()

void QTreeView::setWordWrap ( bool  on)

Definition at line 958 of file qtreeview.cpp.

◆ showColumn

void QTreeView::showColumn ( int  column)
slot

Shows the given column in the tree view.

See also
hideColumn(), setColumnHidden()

Definition at line 746 of file qtreeview.cpp.

Here is the call graph for this function:

◆ sizeHintForColumn()

int QTreeView::sizeHintForColumn ( int  column) const
overrideprotectedvirtual

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.

See also
QWidget::sizeHint, header(), QHeaderView::resizeContentsPrecision()

Reimplemented from QAbstractItemView.

Definition at line 2886 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sortByColumn

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

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.

See also
sortingEnabled

Definition at line 2629 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ timerEvent()

void QTreeView::timerEvent ( QTimerEvent event)
overrideprotected

\reimp

Definition at line 1259 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ treePosition()

int QTreeView::treePosition ( ) const
Since
5.2

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.

See also
setTreePosition()

Definition at line 998 of file qtreeview.cpp.

◆ uniformRowHeights()

bool QTreeView::uniformRowHeights ( ) const

Definition at line 444 of file qtreeview.cpp.

◆ updateGeometries()

void QTreeView::updateGeometries ( )
overrideprotectedvirtual

\reimp

Reimplemented from QAbstractItemView.

Definition at line 2849 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ verticalOffset()

int QTreeView::verticalOffset ( ) const
overrideprotectedvirtual

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

See also
horizontalOffset()

Implements QAbstractItemView.

Definition at line 2177 of file qtreeview.cpp.

Here is the caller graph for this function:

◆ verticalScrollbarValueChanged

void QTreeView::verticalScrollbarValueChanged ( int  value)
overrideprotectedslot

Definition at line 4085 of file qtreeview.cpp.

Here is the call graph for this function:

◆ viewportEvent()

bool QTreeView::viewportEvent ( QEvent event)
overrideprotected

\reimp

\reimp

Definition at line 1308 of file qtreeview.cpp.

Here is the call graph for this function:

◆ viewportSizeHint()

QSize QTreeView::viewportSizeHint ( ) const
overrideprotected

\reimp

Definition at line 2664 of file qtreeview.cpp.

Here is the call graph for this function:

◆ visualRect()

QRect QTreeView::visualRect ( const QModelIndex index) const
overridevirtual

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.

Implements QAbstractItemView.

Definition at line 1104 of file qtreeview.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ visualRegionForSelection()

QRegion QTreeView::visualRegionForSelection ( const QItemSelection selection) const
overrideprotectedvirtual

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.

Implements QAbstractItemView.

Definition at line 2373 of file qtreeview.cpp.

Here is the call graph for this function:

◆ wordWrap()

bool QTreeView::wordWrap ( ) const

Definition at line 967 of file qtreeview.cpp.

Friends And Related Function Documentation

◆ ::tst_QTreeView

friend class ::tst_QTreeView
friend

Definition at line 226 of file qtreeview.h.

◆ QAccessibleTable

friend class QAccessibleTable
friend

Definition at line 227 of file qtreeview.h.

◆ QAccessibleTableCell

friend class QAccessibleTableCell
friend

Definition at line 229 of file qtreeview.h.

◆ QAccessibleTree

friend class QAccessibleTree
friend

Definition at line 228 of file qtreeview.h.

Property Documentation

◆ allColumnsShowFocus

QTreeView::allColumnsShowFocus
readwrite

whether items should show keyboard focus using all columns

Since
4.2

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

The default is false.

Definition at line 241 of file qtreeview.h.

◆ animated

QTreeView::animated
readwrite

whether animations are enabled

Since
4.2

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.

Definition at line 241 of file qtreeview.h.

◆ autoExpandDelay

QTreeView::autoExpandDelay
readwrite

The delay time before items in a tree are opened during a drag and drop operation.

Since
4.3

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.

Definition at line 241 of file qtreeview.h.

◆ expandsOnDoubleClick

QTreeView::expandsOnDoubleClick
readwrite

whether the items can be expanded by double-clicking.

Since
4.4

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

See also
itemsExpandable

Definition at line 241 of file qtreeview.h.

◆ headerHidden

QTreeView::headerHidden
readwrite

whether the header is shown or not.

Since
4.4

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

See also
header()

Definition at line 241 of file qtreeview.h.

◆ indentation

QTreeView::indentation
readwrite

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.

Definition at line 241 of file qtreeview.h.

◆ itemsExpandable

QTreeView::itemsExpandable
readwrite

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.

Definition at line 241 of file qtreeview.h.

◆ rootIsDecorated

QTreeView::rootIsDecorated
readwrite

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.

Definition at line 241 of file qtreeview.h.

◆ sortingEnabled

QTreeView::sortingEnabled
readwrite

whether sorting is enabled

Since
4.2

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.
See also
sortByColumn()

Definition at line 241 of file qtreeview.h.

◆ uniformRowHeights

QTreeView::uniformRowHeights
readwrite

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.

Definition at line 241 of file qtreeview.h.

◆ wordWrap

QTreeView::wordWrap
readwrite

the item text word-wrapping policy

Since
4.3

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 \l{QAbstractItemView::}{textElideMode}.

Definition at line 241 of file qtreeview.h.


The documentation for this class was generated from the following files: