QtBase
v6.3.1
|
The QTreeWidget class provides a tree view that uses a predefined tree model. More...
#include <qtreewidget.h>
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) |
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 |
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.
Definition at line 249 of file qtreewidget.h.
Constructs a tree widget with the given parent.
Definition at line 2574 of file qtreewidget.cpp.
QTreeWidget::~QTreeWidget | ( | ) |
Destroys the tree widget and all its items.
Definition at line 2609 of file qtreewidget.cpp.
void QTreeWidget::addTopLevelItem | ( | QTreeWidgetItem * | item | ) |
Appends the item as a top-level item in the widget.
Definition at line 2703 of file qtreewidget.cpp.
void QTreeWidget::addTopLevelItems | ( | const QList< QTreeWidgetItem * > & | items | ) |
Appends the list of items as a top-level items in the widget.
Definition at line 2754 of file qtreewidget.cpp.
|
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.
Definition at line 3176 of file qtreewidget.cpp.
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.
Definition at line 2987 of file qtreewidget.cpp.
|
slot |
Closes the item. This causes the tree containing the item's children to be collapsed.
Definition at line 3160 of file qtreewidget.cpp.
int QTreeWidget::columnCount | ( | ) | const |
Definition at line 2619 of file qtreewidget.cpp.
int QTreeWidget::currentColumn | ( | ) | const |
Definition at line 2844 of file qtreewidget.cpp.
QTreeWidgetItem * QTreeWidget::currentItem | ( | ) | const |
Returns the current item in the tree widget.
Definition at line 2832 of file qtreewidget.cpp.
|
signal |
This signal is emitted when the current item changes. The current item is specified by current, and this replaces the previous current item.
|
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
.
Definition at line 3237 of file qtreewidget.cpp.
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.
|
overrideprotected |
\reimp
Definition at line 3359 of file qtreewidget.cpp.
|
slot |
Expands the item. This causes the tree containing the item's children to be expanded.
Definition at line 3147 of file qtreewidget.cpp.
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.
QTreeWidgetItem * QTreeWidget::headerItem | ( | ) | const |
Returns the item used for the tree widget's header.
Definition at line 2765 of file qtreewidget.cpp.
QModelIndex QTreeWidget::indexFromItem | ( | const QTreeWidgetItem * | item, |
int | column = 0 |
||
) | const |
Returns the QModelIndex associated with the given item in the given column.
{const} item.Definition at line 3262 of file qtreewidget.cpp.
int QTreeWidget::indexOfTopLevelItem | ( | QTreeWidgetItem * | item | ) | const |
Returns the index of the given top-level item, or -1 if the item cannot be found.
Definition at line 2727 of file qtreewidget.cpp.
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.
Definition at line 2690 of file qtreewidget.cpp.
void QTreeWidget::insertTopLevelItems | ( | int | index, |
const QList< QTreeWidgetItem * > & | items | ||
) |
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.
Definition at line 2743 of file qtreewidget.cpp.
QTreeWidgetItem * QTreeWidget::invisibleRootItem | ( | ) | const |
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.
bool QAbstractItemView::isPersistentEditorOpen |
Returns whether a persistent editor is open for the item at index index.
Definition at line 218 of file qabstractitemview.cpp.
bool QTreeWidget::isPersistentEditorOpen | ( | QTreeWidgetItem * | item, |
int | column = 0 |
||
) | const |
Returns whether a persistent editor is open for item item in column column.
Definition at line 3002 of file qtreewidget.cpp.
QTreeWidgetItem * QTreeWidget::itemAbove | ( | const QTreeWidgetItem * | item | ) | const |
Returns the item above the given item.
Definition at line 3092 of file qtreewidget.cpp.
|
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.
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()}.
Definition at line 2895 of file qtreewidget.cpp.
|
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.
QTreeWidgetItem * QTreeWidget::itemBelow | ( | const QTreeWidgetItem * | item | ) | const |
Returns the item visually below the given item.
Definition at line 3107 of file qtreewidget.cpp.
|
signal |
This signal is emitted when the contents of the column in the specified item changes.
|
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.
|
signal |
This signal is emitted when the specified item is collapsed so that none of its children are displayed.
|
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.
|
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.
|
signal |
This signal is emitted when the specified item is expanded so that all of its children are displayed.
QTreeWidgetItem * QTreeWidget::itemFromIndex | ( | const QModelIndex & | index | ) | const |
Returns a pointer to the QTreeWidgetItem associated with the given index.
Definition at line 3273 of file qtreewidget.cpp.
|
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.
|
signal |
This signal is emitted when the selection changes in the tree widget. The current selection can be found with selectedItems().
QWidget * QTreeWidget::itemWidget | ( | QTreeWidgetItem * | item, |
int | column | ||
) | const |
Returns the widget displayed in the cell specified by item and the given column.
Definition at line 3014 of file qtreewidget.cpp.
|
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.
|
protectedvirtual |
Returns a list of MIME types that can be used to describe a list of treewidget items.
Definition at line 3189 of file qtreewidget.cpp.
void QTreeWidget::openPersistentEditor | ( | QTreeWidgetItem * | item, |
int | column = 0 |
||
) |
Opens a persistent editor for the item in the given column.
Definition at line 2972 of file qtreewidget.cpp.
|
inline |
Removes the widget set in the given item in the given column.
Definition at line 365 of file qtreewidget.h.
|
slot |
Ensures that the item is visible, scrolling the view if necessary using the specified hint.
Definition at line 3135 of file qtreewidget.cpp.
QList< QTreeWidgetItem * > QTreeWidget::selectedItems | ( | ) | const |
Returns a list of all selected non-hidden items.
Definition at line 3054 of file qtreewidget.cpp.
void QTreeWidget::setColumnCount | ( | int | columns | ) |
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.
Definition at line 2857 of file qtreewidget.cpp.
void QTreeWidget::setCurrentItem | ( | QTreeWidgetItem * | item, |
int | column | ||
) |
Definition at line 2868 of file qtreewidget.cpp.
void QTreeWidget::setCurrentItem | ( | QTreeWidgetItem * | item, |
int | column, | ||
QItemSelectionModel::SelectionFlags | command | ||
) |
Definition at line 2881 of file qtreewidget.cpp.
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.
Definition at line 2780 of file qtreewidget.cpp.
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.
Definition at line 2810 of file qtreewidget.cpp.
void QTreeWidget::setItemWidget | ( | QTreeWidgetItem * | item, |
int | column, | ||
QWidget * | widget | ||
) |
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.
Definition at line 3043 of file qtreewidget.cpp.
|
overridevirtual |
\reimp
Reimplemented from QTreeView.
Definition at line 3120 of file qtreewidget.cpp.
int QTreeWidget::sortColumn | ( | ) | const |
Returns the column used to sort the contents of the widget.
Definition at line 2934 of file qtreewidget.cpp.
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.
Definition at line 2949 of file qtreewidget.cpp.
|
protectedvirtual |
Returns the drop actions supported by this view.
Definition at line 3250 of file qtreewidget.cpp.
QTreeWidgetItem * QTreeWidget::takeTopLevelItem | ( | int | index | ) |
Removes the top-level item at the given index in the tree and returns it, otherwise returns \nullptr;
Definition at line 2715 of file qtreewidget.cpp.
QTreeWidgetItem * QTreeWidget::topLevelItem | ( | int | index | ) | const |
Returns the top level item at the given index, or \nullptr if the item does not exist.
Definition at line 2661 of file qtreewidget.cpp.
int QTreeWidget::topLevelItemCount | ( | ) | const |
Definition at line 2676 of file qtreewidget.cpp.
QRect QTreeWidget::visualItemRect | ( | const QTreeWidgetItem * | item | ) | const |
Returns the rectangle on the viewport occupied by the item at item.
Definition at line 2914 of file qtreewidget.cpp.
|
friend |
Definition at line 255 of file qtreewidget.h.
|
friend |
Definition at line 256 of file qtreewidget.h.
|
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.
|
read |
the number of top-level items
By default, this property has a value of 0.
Definition at line 211 of file qtreewidget.h.