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

The QTreeWidget class provides a tree view that uses a predefined tree model. More...

#include <qtreewidget.h>

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

Public Slots

void scrollToItem (const QTreeWidgetItem *item, QAbstractItemView::ScrollHint hint=EnsureVisible)
 
void expandItem (const QTreeWidgetItem *item)
 
void collapseItem (const QTreeWidgetItem *item)
 
void clear ()
 
- Public Slots inherited from QTreeView
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 itemPressed (QTreeWidgetItem *item, int column)
 
void itemClicked (QTreeWidgetItem *item, int column)
 
void itemDoubleClicked (QTreeWidgetItem *item, int column)
 
void itemActivated (QTreeWidgetItem *item, int column)
 
void itemEntered (QTreeWidgetItem *item, int column)
 
void itemChanged (QTreeWidgetItem *item, int column)
 
void itemExpanded (QTreeWidgetItem *item)
 
void itemCollapsed (QTreeWidgetItem *item)
 
void currentItemChanged (QTreeWidgetItem *current, QTreeWidgetItem *previous)
 
void itemSelectionChanged ()
 
- Signals inherited from QTreeView
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

 QTreeWidget (QWidget *parent=nullptr)
 
 ~QTreeWidget ()
 
int columnCount () const
 
void setColumnCount (int columns)
 
QTreeWidgetIteminvisibleRootItem () const
 
QTreeWidgetItemtopLevelItem (int index) const
 
int topLevelItemCount () const
 
void insertTopLevelItem (int index, QTreeWidgetItem *item)
 
void addTopLevelItem (QTreeWidgetItem *item)
 
QTreeWidgetItemtakeTopLevelItem (int index)
 
int indexOfTopLevelItem (QTreeWidgetItem *item) const
 
void insertTopLevelItems (int index, const QList< QTreeWidgetItem * > &items)
 
void addTopLevelItems (const QList< QTreeWidgetItem * > &items)
 
QTreeWidgetItemheaderItem () const
 
void setHeaderItem (QTreeWidgetItem *item)
 
void setHeaderLabels (const QStringList &labels)
 
void setHeaderLabel (const QString &label)
 
QTreeWidgetItemcurrentItem () const
 
int currentColumn () const
 
void setCurrentItem (QTreeWidgetItem *item)
 
void setCurrentItem (QTreeWidgetItem *item, int column)
 
void setCurrentItem (QTreeWidgetItem *item, int column, QItemSelectionModel::SelectionFlags command)
 
QTreeWidgetItemitemAt (const QPoint &p) const
 
QTreeWidgetItemitemAt (int x, int y) const
 
QRect visualItemRect (const QTreeWidgetItem *item) const
 
int sortColumn () const
 
void sortItems (int column, Qt::SortOrder order)
 
void editItem (QTreeWidgetItem *item, int column=0)
 
void openPersistentEditor (QTreeWidgetItem *item, int column=0)
 
void closePersistentEditor (QTreeWidgetItem *item, int column=0)
 
bool isPersistentEditorOpen (QTreeWidgetItem *item, int column=0) const
 
QWidgetitemWidget (QTreeWidgetItem *item, int column) const
 
void setItemWidget (QTreeWidgetItem *item, int column, QWidget *widget)
 
void removeItemWidget (QTreeWidgetItem *item, int column)
 
QList< QTreeWidgetItem * > selectedItems () const
 
QList< QTreeWidgetItem * > findItems (const QString &text, Qt::MatchFlags flags, int column=0) const
 
QTreeWidgetItemitemAbove (const QTreeWidgetItem *item) const
 
QTreeWidgetItemitemBelow (const QTreeWidgetItem *item) const
 
QModelIndex indexFromItem (const QTreeWidgetItem *item, int column=0) const
 
QTreeWidgetItemitemFromIndex (const QModelIndex &index) const
 
void setSelectionModel (QItemSelectionModel *selectionModel) override
 
bool isPersistentEditorOpen (const QModelIndex &index) const
 
- Public Member Functions inherited from QTreeView
 QTreeView (QWidget *parent=nullptr)
 
 ~QTreeView ()
 
void setRootIndex (const QModelIndex &index) 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 Member Functions

bool event (QEvent *e) override
 
virtual QStringList mimeTypes () const
 
virtual QMimeDatamimeData (const QList< QTreeWidgetItem * > &items) const
 
virtual bool dropMimeData (QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
 
virtual Qt::DropActions supportedDropActions () const
 
- Protected Member Functions inherited from QTreeView
 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 columnCount
 the number of columns displayed in the tree widget More...
 
int topLevelItemCount
 the number of top-level items More...
 
- Properties inherited from QTreeView
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 QTreeModel
 
class QTreeWidgetItem
 

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
}
 
- Protected Slots inherited from QTreeView
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)
 

Detailed Description

The QTreeWidget class provides a tree view that uses a predefined tree model.

\inmodule QtWidgets

The QTreeWidget class is a convenience class that provides a standard tree widget with a classic item-based interface similar to that used by the QListView class in Qt 3. This class is based on Qt's Model/View architecture and uses a default model to hold items, each of which is a QTreeWidgetItem.

Developers who do not need the flexibility of the Model/View framework can use this class to create simple hierarchical lists very easily. A more flexible approach involves combining a QTreeView with a standard item model. This allows the storage of data to be separated from its representation.

In its simplest form, a tree widget can be constructed in the following way:

Before items can be added to the tree widget, the number of columns must be set with setColumnCount(). This allows each item to have one or more labels or other decorations. The number of columns in use can be found with the columnCount() function.

The tree can have a header that contains a section for each column in the widget. It is easiest to set up the labels for each section by supplying a list of strings with setHeaderLabels(), but a custom header can be constructed with a QTreeWidgetItem and inserted into the tree with the setHeaderItem() function.

The items in the tree can be sorted by column according to a predefined sort order. If sorting is enabled, the user can sort the items by clicking on a column header. Sorting can be enabled or disabled by calling \l{QTreeView::setSortingEnabled()}{setSortingEnabled()}. The \l{QTreeView::isSortingEnabled()}{isSortingEnabled()} function indicates whether sorting is enabled.

See also
QTreeWidgetItem, QTreeWidgetItemIterator, QTreeView, {Model/View Programming}, {Settings Editor Example}

Definition at line 249 of file qtreewidget.h.

Constructor & Destructor Documentation

◆ QTreeWidget()

QTreeWidget::QTreeWidget ( QWidget parent = nullptr)
explicit

Constructs a tree widget with the given parent.

Definition at line 2574 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ ~QTreeWidget()

QTreeWidget::~QTreeWidget ( )

Destroys the tree widget and all its items.

Definition at line 2609 of file qtreewidget.cpp.

Member Function Documentation

◆ addTopLevelItem()

void QTreeWidget::addTopLevelItem ( QTreeWidgetItem item)
Since
4.1

Appends the item as a top-level item in the widget.

See also
insertTopLevelItem()

Definition at line 2703 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ addTopLevelItems()

void QTreeWidget::addTopLevelItems ( const QList< QTreeWidgetItem * > &  items)

Appends the list of items as a top-level items in the widget.

See also
insertTopLevelItems()

Definition at line 2754 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ clear

void QTreeWidget::clear ( )
slot

Clears the tree widget by removing all of its items and selections.

{Note:} Since each item is removed from the tree widget before being deleted, the return value of QTreeWidgetItem::treeWidget() will be invalid when called from an item's destructor.

See also
takeTopLevelItem(), topLevelItemCount(), columnCount()

Definition at line 3176 of file qtreewidget.cpp.

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

◆ closePersistentEditor()

void QTreeWidget::closePersistentEditor ( QTreeWidgetItem item,
int  column = 0 
)

Closes the persistent editor for the item in the given column.

This function has no effect if no persistent editor is open for this combination of item and column.

See also
openPersistentEditor(), isPersistentEditorOpen()

Definition at line 2987 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ collapseItem

void QTreeWidget::collapseItem ( const QTreeWidgetItem item)
slot

Closes the item. This causes the tree containing the item's children to be collapsed.

See also
expandItem(), currentItem(), itemAt(), topLevelItem()

Definition at line 3160 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ columnCount()

int QTreeWidget::columnCount ( ) const

Definition at line 2619 of file qtreewidget.cpp.

◆ currentColumn()

int QTreeWidget::currentColumn ( ) const
Since
4.1 Returns the current column in the tree widget.
See also
setCurrentItem(), columnCount()

Definition at line 2844 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ currentItem()

QTreeWidgetItem * QTreeWidget::currentItem ( ) const

Returns the current item in the tree widget.

See also
setCurrentItem(), currentItemChanged()

Definition at line 2832 of file qtreewidget.cpp.

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

◆ currentItemChanged

void QTreeWidget::currentItemChanged ( QTreeWidgetItem current,
QTreeWidgetItem previous 
)
signal

This signal is emitted when the current item changes. The current item is specified by current, and this replaces the previous current item.

See also
setCurrentItem()

◆ dropMimeData()

bool QTreeWidget::dropMimeData ( QTreeWidgetItem parent,
int  index,
const QMimeData data,
Qt::DropAction  action 
)
protectedvirtual

Handles the data supplied by a drag and drop operation that ended with the given action in the index in the given parent item.

The default implementation returns true if the drop was successfully handled by decoding the mime data and inserting it into the model; otherwise it returns false.

See also
supportedDropActions()

Definition at line 3237 of file qtreewidget.cpp.

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

◆ editItem()

void QTreeWidget::editItem ( QTreeWidgetItem item,
int  column = 0 
)

Starts editing the item in the given column if it is editable.

Definition at line 2960 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ event()

bool QTreeWidget::event ( QEvent e)
overrideprotected

\reimp

Definition at line 3359 of file qtreewidget.cpp.

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

◆ expandItem

void QTreeWidget::expandItem ( const QTreeWidgetItem item)
slot

Expands the item. This causes the tree containing the item's children to be expanded.

See also
collapseItem(), currentItem(), itemAt(), topLevelItem(), itemExpanded()

Definition at line 3147 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ findItems()

QList< QTreeWidgetItem * > QTreeWidget::findItems ( const QString text,
Qt::MatchFlags  flags,
int  column = 0 
) const

Returns a list of items that match the given text, using the given flags, in the given column.

Definition at line 3073 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ headerItem()

QTreeWidgetItem * QTreeWidget::headerItem ( ) const

Returns the item used for the tree widget's header.

See also
setHeaderItem()

Definition at line 2765 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ indexFromItem()

QModelIndex QTreeWidget::indexFromItem ( const QTreeWidgetItem item,
int  column = 0 
) const

Returns the QModelIndex associated with the given item in the given column.

Note
In Qt versions prior to 5.7, this function took a non-{const} item.
See also
itemFromIndex(), topLevelItem()

Definition at line 3262 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ indexOfTopLevelItem()

int QTreeWidget::indexOfTopLevelItem ( QTreeWidgetItem item) const

Returns the index of the given top-level item, or -1 if the item cannot be found.

See also
sortItems(), topLevelItemCount()

Definition at line 2727 of file qtreewidget.cpp.

◆ insertTopLevelItem()

void QTreeWidget::insertTopLevelItem ( int  index,
QTreeWidgetItem item 
)

Inserts the item at index in the top level in the view.

If the item has already been inserted somewhere else it won't be inserted.

See also
addTopLevelItem(), columnCount()

Definition at line 2690 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ insertTopLevelItems()

void QTreeWidget::insertTopLevelItems ( int  index,
const QList< QTreeWidgetItem * > &  items 
)
Since
4.1

Inserts the list of items at index in the top level in the view.

Items that have already been inserted somewhere else won't be inserted.

See also
addTopLevelItems()

Definition at line 2743 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ invisibleRootItem()

QTreeWidgetItem * QTreeWidget::invisibleRootItem ( ) const
Since
4.2

Returns the tree widget's invisible root item.

The invisible root item provides access to the tree widget's top-level items through the QTreeWidgetItem API, making it possible to write functions that can treat top-level items and their children in a uniform way; for example, recursive functions.

Definition at line 2648 of file qtreewidget.cpp.

◆ isPersistentEditorOpen() [1/2]

bool QAbstractItemView::isPersistentEditorOpen
Since
5.10

Returns whether a persistent editor is open for the item at index index.

See also
openPersistentEditor(), closePersistentEditor()

Definition at line 218 of file qabstractitemview.cpp.

◆ isPersistentEditorOpen() [2/2]

bool QTreeWidget::isPersistentEditorOpen ( QTreeWidgetItem item,
int  column = 0 
) const
Since
5.10

Returns whether a persistent editor is open for item item in column column.

See also
openPersistentEditor(), closePersistentEditor()

Definition at line 3002 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ itemAbove()

QTreeWidgetItem * QTreeWidget::itemAbove ( const QTreeWidgetItem item) const
Since
4.3

Returns the item above the given item.

Definition at line 3092 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ itemActivated

void QTreeWidget::itemActivated ( QTreeWidgetItem item,
int  column 
)
signal

This signal is emitted when the user activates an item by single- or double-clicking (depending on the platform, i.e. on the QStyle::SH_ItemView_ActivateItemOnSingleClick style hint) or pressing a special key (e.g., \uicontrol Enter).

The specified item is the item that was clicked, or \nullptr if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.

◆ itemAt() [1/2]

QTreeWidgetItem * QTreeWidget::itemAt ( const QPoint p) const

Returns a pointer to the item at the coordinates p. The coordinates are relative to the tree widget's \l{QAbstractScrollArea::}{viewport()}.

See also
visualItemRect()

Definition at line 2895 of file qtreewidget.cpp.

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

◆ itemAt() [2/2]

QTreeWidgetItem * QTreeWidget::itemAt ( int  x,
int  y 
) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a pointer to the item at the coordinates (x, y). The coordinates are relative to the tree widget's \l{QAbstractScrollArea::}{viewport()}.

Definition at line 368 of file qtreewidget.h.

◆ itemBelow()

QTreeWidgetItem * QTreeWidget::itemBelow ( const QTreeWidgetItem item) const
Since
4.3

Returns the item visually below the given item.

Definition at line 3107 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ itemChanged

void QTreeWidget::itemChanged ( QTreeWidgetItem item,
int  column 
)
signal

This signal is emitted when the contents of the column in the specified item changes.

Here is the caller graph for this function:

◆ itemClicked

void QTreeWidget::itemClicked ( QTreeWidgetItem item,
int  column 
)
signal

This signal is emitted when the user clicks inside the widget.

The specified item is the item that was clicked. The column is the item's column that was clicked. If no item was clicked, no signal will be emitted.

Here is the caller graph for this function:

◆ itemCollapsed

void QTreeWidget::itemCollapsed ( QTreeWidgetItem item)
signal

This signal is emitted when the specified item is collapsed so that none of its children are displayed.

Note
This signal will not be emitted if an item changes its state when collapseAll() is invoked.
See also
QTreeWidgetItem::isExpanded(), itemExpanded(), collapseItem()

◆ itemDoubleClicked

void QTreeWidget::itemDoubleClicked ( QTreeWidgetItem item,
int  column 
)
signal

This signal is emitted when the user double clicks inside the widget.

The specified item is the item that was clicked, or \nullptr if no item was clicked. The column is the item's column that was clicked. If no item was double clicked, no signal will be emitted.

◆ itemEntered

void QTreeWidget::itemEntered ( QTreeWidgetItem item,
int  column 
)
signal

This signal is emitted when the mouse cursor enters an item over the specified column. QTreeWidget mouse tracking needs to be enabled for this feature to work.

◆ itemExpanded

void QTreeWidget::itemExpanded ( QTreeWidgetItem item)
signal

This signal is emitted when the specified item is expanded so that all of its children are displayed.

See also
QTreeWidgetItem::isExpanded(), itemCollapsed(), expandItem()

◆ itemFromIndex()

QTreeWidgetItem * QTreeWidget::itemFromIndex ( const QModelIndex index) const

Returns a pointer to the QTreeWidgetItem associated with the given index.

See also
indexFromItem()

Definition at line 3273 of file qtreewidget.cpp.

◆ itemPressed

void QTreeWidget::itemPressed ( QTreeWidgetItem item,
int  column 
)
signal

This signal is emitted when the user presses a mouse button inside the widget.

The specified item is the item that was clicked, or \nullptr if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.

◆ itemSelectionChanged

void QTreeWidget::itemSelectionChanged ( )
signal

This signal is emitted when the selection changes in the tree widget. The current selection can be found with selectedItems().

◆ itemWidget()

QWidget * QTreeWidget::itemWidget ( QTreeWidgetItem item,
int  column 
) const
Since
4.1

Returns the widget displayed in the cell specified by item and the given column.

Definition at line 3014 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ mimeData()

QMimeData * QTreeWidget::mimeData ( const QList< QTreeWidgetItem * > &  items) const
protectedvirtual

Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes() function.

If the list of items is empty, \nullptr is returned rather than a serialized empty list.

Definition at line 3202 of file qtreewidget.cpp.

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

◆ mimeTypes()

QStringList QTreeWidget::mimeTypes ( ) const
protectedvirtual

Returns a list of MIME types that can be used to describe a list of treewidget items.

See also
mimeData()

Definition at line 3189 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ openPersistentEditor()

void QTreeWidget::openPersistentEditor ( QTreeWidgetItem item,
int  column = 0 
)

Opens a persistent editor for the item in the given column.

See also
closePersistentEditor(), isPersistentEditorOpen()

Definition at line 2972 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ removeItemWidget()

void QTreeWidget::removeItemWidget ( QTreeWidgetItem item,
int  column 
)
inline
Since
4.3

Removes the widget set in the given item in the given column.

Definition at line 365 of file qtreewidget.h.

◆ scrollToItem

void QTreeWidget::scrollToItem ( const QTreeWidgetItem item,
QAbstractItemView::ScrollHint  hint = EnsureVisible 
)
slot

Ensures that the item is visible, scrolling the view if necessary using the specified hint.

See also
currentItem(), itemAt(), topLevelItem()

Definition at line 3135 of file qtreewidget.cpp.

◆ selectedItems()

QList< QTreeWidgetItem * > QTreeWidget::selectedItems ( ) const

Returns a list of all selected non-hidden items.

See also
itemSelectionChanged()

Definition at line 3054 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ setColumnCount()

void QTreeWidget::setColumnCount ( int  columns)

Definition at line 2629 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ setCurrentItem() [1/3]

void QTreeWidget::setCurrentItem ( QTreeWidgetItem item)

Sets the current item in the tree widget.

Unless the selection mode is \l{QAbstractItemView::}{NoSelection}, the item is also selected.

See also
currentItem(), currentItemChanged()

Definition at line 2857 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ setCurrentItem() [2/3]

void QTreeWidget::setCurrentItem ( QTreeWidgetItem item,
int  column 
)
Since
4.1 Sets the current item in the tree widget and the current column to column.
See also
currentItem()

Definition at line 2868 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ setCurrentItem() [3/3]

void QTreeWidget::setCurrentItem ( QTreeWidgetItem item,
int  column,
QItemSelectionModel::SelectionFlags  command 
)
Since
4.4 Sets the current item in the tree widget and the current column to column, using the given command.
See also
currentItem()

Definition at line 2881 of file qtreewidget.cpp.

◆ setHeaderItem()

void QTreeWidget::setHeaderItem ( QTreeWidgetItem item)

Sets the header item for the tree widget. The label for each column in the header is supplied by the corresponding label in the item.

The tree widget takes ownership of the item.

See also
headerItem(), setHeaderLabels()

Definition at line 2780 of file qtreewidget.cpp.

◆ setHeaderLabel()

void QTreeWidget::setHeaderLabel ( const QString label)
inline
Since
4.2

Same as setHeaderLabels(QStringList(label)).

Definition at line 371 of file qtreewidget.h.

◆ setHeaderLabels()

void QTreeWidget::setHeaderLabels ( const QStringList labels)

Adds a column in the header for each item in the labels list, and sets the label for each column.

Note that setHeaderLabels() won't remove existing columns.

See also
setHeaderItem(), setHeaderLabel()

Definition at line 2810 of file qtreewidget.cpp.

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

◆ setItemWidget()

void QTreeWidget::setItemWidget ( QTreeWidgetItem item,
int  column,
QWidget widget 
)
Since
4.1

Sets the given widget to be displayed in the cell specified by the given item and column.

The given widget's \l {QWidget::}{autoFillBackground} property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the tree widget item.

This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView and subclass QStyledItemDelegate instead.

This function cannot be called before the item hierarchy has been set up, i.e., the QTreeWidgetItem that will hold widget must have been added to the view before widget is set.

Note
The tree takes ownership of the widget.
See also
{Delegate Classes}

Definition at line 3043 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ setSelectionModel()

void QTreeWidget::setSelectionModel ( QItemSelectionModel selectionModel)
overridevirtual

\reimp

Reimplemented from QTreeView.

Definition at line 3120 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ sortColumn()

int QTreeWidget::sortColumn ( ) const
Since
4.1

Returns the column used to sort the contents of the widget.

See also
sortItems()

Definition at line 2934 of file qtreewidget.cpp.

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

◆ sortItems()

void QTreeWidget::sortItems ( int  column,
Qt::SortOrder  order 
)

Sorts the items in the widget in the specified order by the values in the given column.

See also
sortColumn()

Definition at line 2949 of file qtreewidget.cpp.

Here is the call graph for this function:

◆ supportedDropActions()

Qt::DropActions QTreeWidget::supportedDropActions ( ) const
protectedvirtual

Returns the drop actions supported by this view.

See also
Qt::DropActions

Definition at line 3250 of file qtreewidget.cpp.

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

◆ takeTopLevelItem()

QTreeWidgetItem * QTreeWidget::takeTopLevelItem ( int  index)

Removes the top-level item at the given index in the tree and returns it, otherwise returns \nullptr;

See also
insertTopLevelItem(), topLevelItem(), topLevelItemCount()

Definition at line 2715 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ topLevelItem()

QTreeWidgetItem * QTreeWidget::topLevelItem ( int  index) const

Returns the top level item at the given index, or \nullptr if the item does not exist.

See also
topLevelItemCount(), insertTopLevelItem()

Definition at line 2661 of file qtreewidget.cpp.

Here is the caller graph for this function:

◆ topLevelItemCount()

int QTreeWidget::topLevelItemCount ( ) const

Definition at line 2676 of file qtreewidget.cpp.

◆ visualItemRect()

QRect QTreeWidget::visualItemRect ( const QTreeWidgetItem item) const

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

See also
itemAt()

Definition at line 2914 of file qtreewidget.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ QTreeModel

friend class QTreeModel
friend

Definition at line 255 of file qtreewidget.h.

◆ QTreeWidgetItem

friend class QTreeWidgetItem
friend

Definition at line 256 of file qtreewidget.h.

Property Documentation

◆ columnCount

QTreeWidget::columnCount
readwrite

the number of columns displayed in the tree widget

By default, this property has a value of 1.

Definition at line 211 of file qtreewidget.h.

◆ topLevelItemCount

QTreeWidget::topLevelItemCount
read

the number of top-level items

By default, this property has a value of 0.

See also
columnCount(), currentItem()

Definition at line 211 of file qtreewidget.h.


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