![]() |
Qt 6.x
The Qt SDK
|
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) |
Ensures that the item is visible, scrolling the view if necessary using the specified hint. | |
void | expandItem (const QTreeWidgetItem *item) |
Expands the item. | |
void | collapseItem (const QTreeWidgetItem *item) |
Closes the item. | |
void | clear () |
Clears the tree widget by removing all of its items and selections. | |
![]() | |
void | hideColumn (int column) |
Hides the column given. | |
void | showColumn (int column) |
Shows the given column in the tree view. | |
void | expand (const QModelIndex &index) |
Expands the model item specified by the index. | |
void | collapse (const QModelIndex &index) |
Collapses the model item specified by the index. | |
void | resizeColumnToContents (int column) |
Resizes the column given to the size of its contents. | |
void | sortByColumn (int column, Qt::SortOrder order) |
void | expandAll () |
void | expandRecursively (const QModelIndex &index, int depth=-1) |
void | collapseAll () |
void | expandToDepth (int depth) |
![]() | |
virtual void | reset () |
Reset the internal state of the view. | |
virtual void | setRootIndex (const QModelIndex &index) |
Sets the root item to the item at the given index. | |
virtual void | doItemsLayout () |
virtual void | selectAll () |
Selects all items in the view. | |
void | edit (const QModelIndex &index) |
Starts editing the item corresponding to the given index if it is editable. | |
void | clearSelection () |
Deselects all selected items. | |
void | setCurrentIndex (const QModelIndex &index) |
Sets the current item to be the item at index. | |
void | scrollToTop () |
void | scrollToBottom () |
void | update (const QModelIndex &index) |
Signals | |
void | itemPressed (QTreeWidgetItem *item, int column) |
This signal is emitted when the user presses a mouse button inside the widget. | |
void | itemClicked (QTreeWidgetItem *item, int column) |
This signal is emitted when the user clicks inside the widget. | |
void | itemDoubleClicked (QTreeWidgetItem *item, int column) |
This signal is emitted when the user double clicks inside the widget. | |
void | itemActivated (QTreeWidgetItem *item, int column) |
This signal is emitted when the user activates an item by single- or double-clicking (depending on the platform, i.e. | |
void | itemEntered (QTreeWidgetItem *item, int column) |
This signal is emitted when the mouse cursor enters an item over the specified column. | |
void | itemChanged (QTreeWidgetItem *item, int column) |
This signal is emitted when the contents of the column in the specified item changes. | |
void | itemExpanded (QTreeWidgetItem *item) |
This signal is emitted when the specified item is expanded so that all of its children are displayed. | |
void | itemCollapsed (QTreeWidgetItem *item) |
This signal is emitted when the specified item is collapsed so that none of its children are displayed. | |
void | currentItemChanged (QTreeWidgetItem *current, QTreeWidgetItem *previous) |
This signal is emitted when the current item changes. | |
void | itemSelectionChanged () |
This signal is emitted when the selection changes in the tree widget. | |
![]() | |
void | expanded (const QModelIndex &index) |
This signal is emitted when the item specified by index is expanded. | |
void | collapsed (const QModelIndex &index) |
This signal is emitted when the item specified by index is collapsed. | |
![]() | |
void | pressed (const QModelIndex &index) |
This signal is emitted when a mouse button is pressed. | |
void | clicked (const QModelIndex &index) |
This signal is emitted when a mouse button is left-clicked. | |
void | doubleClicked (const QModelIndex &index) |
This signal is emitted when a mouse button is double-clicked. | |
void | activated (const QModelIndex &index) |
This signal is emitted when the item specified by index is activated by the user. | |
void | entered (const QModelIndex &index) |
This signal is emitted when the mouse cursor enters the item specified by index. | |
void | viewportEntered () |
This signal is emitted when the mouse cursor enters the viewport. | |
void | iconSizeChanged (const QSize &size) |
Public Member Functions | |
QTreeWidget (QWidget *parent=nullptr) | |
Constructs a tree widget with the given parent. | |
~QTreeWidget () | |
Destroys the tree widget and all its items. | |
int | columnCount () const |
void | setColumnCount (int columns) |
QTreeWidgetItem * | invisibleRootItem () const |
QTreeWidgetItem * | topLevelItem (int index) const |
Returns the top level item at the given index, or \nullptr if the item does not exist. | |
int | topLevelItemCount () const |
void | insertTopLevelItem (int index, QTreeWidgetItem *item) |
Inserts the item at index in the top level in the view. | |
void | addTopLevelItem (QTreeWidgetItem *item) |
QTreeWidgetItem * | takeTopLevelItem (int index) |
Removes the top-level item at the given index in the tree and returns it, otherwise returns \nullptr;. | |
int | indexOfTopLevelItem (QTreeWidgetItem *item) const |
Returns the index of the given top-level item, or -1 if the item cannot be found. | |
void | insertTopLevelItems (int index, const QList< QTreeWidgetItem * > &items) |
void | addTopLevelItems (const QList< QTreeWidgetItem * > &items) |
Appends the list of items as a top-level items in the widget. | |
QTreeWidgetItem * | headerItem () const |
Returns the item used for the tree widget's header. | |
void | setHeaderItem (QTreeWidgetItem *item) |
Sets the header item for the tree widget. | |
void | setHeaderLabels (const QStringList &labels) |
Adds a column in the header for each item in the labels list, and sets the label for each column. | |
void | setHeaderLabel (const QString &label) |
QTreeWidgetItem * | currentItem () const |
Returns the current item in the tree widget. | |
int | currentColumn () const |
void | setCurrentItem (QTreeWidgetItem *item) |
Sets the current item in the tree widget. | |
void | setCurrentItem (QTreeWidgetItem *item, int column) |
void | setCurrentItem (QTreeWidgetItem *item, int column, QItemSelectionModel::SelectionFlags command) |
QTreeWidgetItem * | itemAt (const QPoint &p) const |
Returns a pointer to the item at the coordinates p. | |
QTreeWidgetItem * | itemAt (int x, int y) const |
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). | |
QRect | visualItemRect (const QTreeWidgetItem *item) const |
Returns the rectangle on the viewport occupied by the item at item. | |
int | sortColumn () const |
void | sortItems (int column, Qt::SortOrder order) |
Sorts the items in the widget in the specified order by the values in the given column. | |
void | editItem (QTreeWidgetItem *item, int column=0) |
Starts editing the item in the given column if it is editable. | |
void | openPersistentEditor (QTreeWidgetItem *item, int column=0) |
Opens a persistent editor for the item in the given column. | |
void | closePersistentEditor (QTreeWidgetItem *item, int column=0) |
Closes the persistent editor for the item in the given column. | |
bool | isPersistentEditorOpen (QTreeWidgetItem *item, int column=0) const |
QWidget * | itemWidget (QTreeWidgetItem *item, int column) const |
void | setItemWidget (QTreeWidgetItem *item, int column, QWidget *widget) |
void | removeItemWidget (QTreeWidgetItem *item, int column) |
QList< QTreeWidgetItem * > | selectedItems () const |
Returns a list of all selected non-hidden items. | |
QList< QTreeWidgetItem * > | 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. | |
QTreeWidgetItem * | itemAbove (const QTreeWidgetItem *item) const |
QTreeWidgetItem * | itemBelow (const QTreeWidgetItem *item) const |
QModelIndex | indexFromItem (const QTreeWidgetItem *item, int column=0) const |
Returns the QModelIndex associated with the given item in the given column. | |
QTreeWidgetItem * | itemFromIndex (const QModelIndex &index) const |
Returns a pointer to the QTreeWidgetItem associated with the given index. | |
void | setSelectionModel (QItemSelectionModel *selectionModel) override |
\reimp | |
bool | isPersistentEditorOpen (const QModelIndex &index) const |
![]() | |
QTreeView (QWidget *parent=nullptr) | |
Constructs a tree view with a parent to represent a model's data. | |
~QTreeView () | |
Destroys the tree view. | |
void | setModel (QAbstractItemModel *model) override |
\reimp | |
void | setRootIndex (const QModelIndex &index) override |
\reimp | |
void | setSelectionModel (QItemSelectionModel *selectionModel) override |
\reimp | |
QHeaderView * | header () const |
Returns the header for the tree view. | |
void | setHeader (QHeaderView *header) |
Sets the header for the tree view, to the given 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 |
Returns the horizontal position of the column in the viewport. | |
int | columnWidth (int column) const |
Returns the width of the column. | |
void | setColumnWidth (int column, int width) |
int | columnAt (int x) const |
Returns the column in the tree view whose header covers the x coordinate given. | |
bool | isColumnHidden (int column) const |
Returns true if the column is hidden; otherwise returns false . | |
void | setColumnHidden (int column, bool hide) |
If hide is true the column is hidden, otherwise the column is shown. | |
bool | isHeaderHidden () const |
void | setHeaderHidden (bool hide) |
bool | isRowHidden (int row, const QModelIndex &parent) const |
Returns true if the item in the given row of the parent is hidden; otherwise returns false . | |
void | 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. | |
bool | isFirstColumnSpanned (int row, const QModelIndex &parent) const |
void | setFirstColumnSpanned (int row, const QModelIndex &parent, bool span) |
bool | isExpanded (const QModelIndex &index) const |
Returns true if the model item index is expanded; otherwise returns false. | |
void | setExpanded (const QModelIndex &index, bool expand) |
Sets the item referred to by index to either collapse or expanded, depending on the value of expanded. | |
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 |
\reimp | |
QRect | visualRect (const QModelIndex &index) const override |
Returns the rectangle on the viewport occupied by the item at index. | |
void | scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible) override |
Scroll the contents of the tree view until the given model item index is visible. | |
QModelIndex | indexAt (const QPoint &p) const override |
\reimp | |
QModelIndex | indexAbove (const QModelIndex &index) const |
Returns the model index of the item above index. | |
QModelIndex | indexBelow (const QModelIndex &index) const |
Returns the model index of the item below index. | |
void | doItemsLayout () override |
void | reset () override |
\reimp | |
void | dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >()) override |
\reimp | |
void | selectAll () override |
\reimp | |
![]() | |
QAbstractItemView (QWidget *parent=nullptr) | |
Constructs an abstract item view with the given parent. | |
~QAbstractItemView () | |
Destroys the view. | |
virtual void | setModel (QAbstractItemModel *model) |
Sets the model for the view to present. | |
QAbstractItemModel * | model () const |
Returns the model that this view is presenting. | |
virtual void | setSelectionModel (QItemSelectionModel *selectionModel) |
Sets the current selection model to the given selectionModel. | |
QItemSelectionModel * | selectionModel () const |
Returns the current selection model. | |
void | setItemDelegate (QAbstractItemDelegate *delegate) |
Sets the item delegate for this view and its model to delegate. | |
QAbstractItemDelegate * | itemDelegate () const |
Returns the item delegate used by this view and model. | |
void | setSelectionMode (QAbstractItemView::SelectionMode mode) |
QAbstractItemView::SelectionMode | selectionMode () const |
void | setSelectionBehavior (QAbstractItemView::SelectionBehavior behavior) |
QAbstractItemView::SelectionBehavior | selectionBehavior () const |
QModelIndex | currentIndex () const |
Returns the model index of the current item. | |
QModelIndex | rootIndex () const |
Returns the model index of the model's root item. | |
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 |
virtual void | keyboardSearch (const QString &search) |
Moves to and selects the item best matching the string search. | |
virtual QRect | visualRect (const QModelIndex &index) const =0 |
Returns the rectangle on the viewport occupied by the item at index. | |
virtual void | scrollTo (const QModelIndex &index, ScrollHint hint=EnsureVisible)=0 |
Scrolls the view if necessary to ensure that the item at index is visible. | |
virtual QModelIndex | indexAt (const QPoint &point) const =0 |
Returns the model index of the item at the viewport coordinates point. | |
QSize | sizeHintForIndex (const QModelIndex &index) const |
Returns the size hint for the item with the specified index or an invalid size for invalid indexes. | |
virtual int | sizeHintForRow (int row) const |
Returns the height size hint for the specified row or -1 if there is no model. | |
virtual int | sizeHintForColumn (int column) const |
Returns the width size hint for the specified column or -1 if there is no model. | |
void | openPersistentEditor (const QModelIndex &index) |
Opens a persistent editor on the item at the given index. | |
void | closePersistentEditor (const QModelIndex &index) |
Closes the persistent editor for the item at the given index. | |
bool | isPersistentEditorOpen (const QModelIndex &index) const |
void | setIndexWidget (const QModelIndex &index, QWidget *widget) |
QWidget * | indexWidget (const QModelIndex &index) const |
void | setItemDelegateForRow (int row, QAbstractItemDelegate *delegate) |
QAbstractItemDelegate * | itemDelegateForRow (int row) const |
void | setItemDelegateForColumn (int column, QAbstractItemDelegate *delegate) |
QAbstractItemDelegate * | itemDelegateForColumn (int column) const |
virtual QAbstractItemDelegate * | itemDelegateForIndex (const QModelIndex &index) const |
virtual QVariant | inputMethodQuery (Qt::InputMethodQuery query) const override |
\reimp | |
Protected Member Functions | |
bool | event (QEvent *e) override |
\reimp | |
virtual QStringList | mimeTypes () const |
Returns a list of MIME types that can be used to describe a list of treewidget items. | |
virtual QMimeData * | mimeData (const QList< QTreeWidgetItem * > &items) const |
Returns an object that contains a serialized description of the specified items. | |
virtual bool | dropMimeData (QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) |
Handles the data supplied by a drag and drop operation that ended with the given action in the index in the given parent item. | |
virtual Qt::DropActions | supportedDropActions () const |
Returns the drop actions supported by this view. | |
![]() | |
QTreeView (QTreeViewPrivate &dd, QWidget *parent=nullptr) | |
void | scrollContentsBy (int dx, int dy) override |
Scrolls the contents of the tree view by (dx, dy). | |
void | rowsInserted (const QModelIndex &parent, int start, int end) override |
Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item. | |
void | rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end) override |
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. | |
QModelIndex | moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override |
Move the cursor in the way described by cursorAction, using the information provided by the button modifiers. | |
int | horizontalOffset () const override |
Returns the horizontal offset of the items in the treeview. | |
int | verticalOffset () const override |
Returns the vertical offset of the items in the tree view. | |
void | setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command) override |
Applies the selection command to the items in or touched by the rectangle, rect. | |
QRegion | visualRegionForSelection (const QItemSelection &selection) const override |
Returns the rectangle from the viewport of the items in the given selection. | |
QModelIndexList | selectedIndexes () const override |
\reimp | |
void | changeEvent (QEvent *event) override |
\reimp | |
void | timerEvent (QTimerEvent *event) override |
\reimp | |
void | paintEvent (QPaintEvent *event) override |
\reimp | |
void | drawTree (QPainter *painter, const QRegion ®ion) const |
virtual void | drawRow (QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const |
Draws the row in the tree view that contains the model item index, using the painter given. | |
virtual void | drawBranches (QPainter *painter, const QRect &rect, const QModelIndex &index) const |
Draws the branches in the tree view on the same row as the model item index, using the painter given. | |
void | mousePressEvent (QMouseEvent *event) override |
\reimp | |
void | mouseReleaseEvent (QMouseEvent *event) override |
\reimp | |
void | mouseDoubleClickEvent (QMouseEvent *event) override |
\reimp | |
void | mouseMoveEvent (QMouseEvent *event) override |
\reimp | |
void | keyPressEvent (QKeyEvent *event) override |
\reimp | |
bool | viewportEvent (QEvent *event) override |
\reimp | |
void | updateGeometries () override |
\reimp | |
QSize | viewportSizeHint () const override |
\reimp | |
int | sizeHintForColumn (int column) const override |
Returns the size hint for the column's width or -1 if there is no model. | |
int | indexRowSizeHint (const QModelIndex &index) const |
Returns the size hint for the row indicated by index. | |
int | rowHeight (const QModelIndex &index) const |
void | horizontalScrollbarAction (int action) override |
bool | isIndexHidden (const QModelIndex &index) const override |
\reimp | |
void | selectionChanged (const QItemSelection &selected, const QItemSelection &deselected) override |
\reimp | |
void | currentChanged (const QModelIndex ¤t, const QModelIndex &previous) override |
\reimp | |
![]() | |
QAbstractItemView (QAbstractItemViewPrivate &, QWidget *parent=nullptr) | |
virtual QModelIndex | moveCursor (CursorAction cursorAction, Qt::KeyboardModifiers modifiers)=0 |
Returns a QModelIndex object pointing to the next object in the view, based on the given cursorAction and keyboard modifiers specified by modifiers. | |
virtual int | horizontalOffset () const =0 |
Returns the horizontal offset of the view. | |
virtual int | verticalOffset () const =0 |
Returns the vertical offset of the view. | |
virtual bool | isIndexHidden (const QModelIndex &index) const =0 |
Returns true if the item referred to by the given index is hidden in the view, otherwise returns false . | |
virtual void | setSelection (const QRect &rect, QItemSelectionModel::SelectionFlags command)=0 |
Applies the selection flags to the items in or touched by the rectangle, rect. | |
virtual QRegion | visualRegionForSelection (const QItemSelection &selection) const =0 |
Returns the region from the viewport of the items in the given selection. | |
virtual QModelIndexList | selectedIndexes () const |
This convenience function returns a list of all selected and non-hidden item indexes in the view. | |
virtual bool | edit (const QModelIndex &index, EditTrigger trigger, QEvent *event) |
Starts editing the item at index, creating an editor if necessary, and returns true if the view's \l{State} is now EditingState; otherwise returns false . | |
virtual QItemSelectionModel::SelectionFlags | selectionCommand (const QModelIndex &index, const QEvent *event=nullptr) const |
Returns the SelectionFlags to be used when updating a selection model for the specified index. | |
virtual void | initViewItemOption (QStyleOptionViewItem *option) const |
State | state () const |
Returns the item view's state. | |
void | setState (State state) |
Sets the item view's state to the given state. | |
void | scheduleDelayedItemsLayout () |
Schedules a layout of the items in the view to be executed when the event processing starts. | |
void | executeDelayedItemsLayout () |
Executes the scheduled layouts without waiting for the event processing to begin. | |
void | setDirtyRegion (const QRegion ®ion) |
void | scrollDirtyRegion (int dx, int dy) |
Prepares the view for scrolling by ({dx},{dy}) pixels by moving the dirty regions in the opposite direction. | |
QPoint | dirtyRegionOffset () const |
Returns the offset of the dirty regions in the view. | |
void | startAutoScroll () |
void | stopAutoScroll () |
void | doAutoScroll () |
bool | focusNextPrevChild (bool next) override |
\reimp | |
bool | event (QEvent *event) override |
\reimp | |
bool | viewportEvent (QEvent *event) override |
This function is used to handle tool tips, and What's This? mode, if the given event is a QEvent::ToolTip,or a QEvent::WhatsThis. | |
void | mousePressEvent (QMouseEvent *event) override |
This function is called with the given event when a mouse button is pressed while the cursor is inside the widget. | |
void | mouseMoveEvent (QMouseEvent *event) override |
This function is called with the given event when a mouse move event is sent to the widget. | |
void | mouseReleaseEvent (QMouseEvent *event) override |
This function is called with the given event when a mouse button is released, after a mouse press event on the widget. | |
void | mouseDoubleClickEvent (QMouseEvent *event) override |
This function is called with the given event when a mouse button is double clicked inside the widget. | |
void | focusInEvent (QFocusEvent *event) override |
This function is called with the given event when the widget obtains the focus. | |
void | focusOutEvent (QFocusEvent *event) override |
This function is called with the given event when the widget loses the focus. | |
void | keyPressEvent (QKeyEvent *event) override |
This function is called with the given event when a key event is sent to the widget. | |
void | resizeEvent (QResizeEvent *event) override |
This function is called with the given event when a resize event is sent to the widget. | |
void | timerEvent (QTimerEvent *event) override |
This function is called with the given event when a timer event is sent to the widget. | |
void | inputMethodEvent (QInputMethodEvent *event) override |
\reimp | |
bool | eventFilter (QObject *object, QEvent *event) override |
\reimp | |
QSize | viewportSizeHint () const override |
Properties | |
int | columnCount |
the number of columns displayed in the tree widget | |
int | topLevelItemCount |
the number of top-level items | |
![]() | |
int | autoExpandDelay |
The delay time before items in a tree are opened during a drag and drop operation. | |
int | indentation |
indentation of the items in the tree view. | |
bool | rootIsDecorated |
whether to show controls for expanding and collapsing top-level items | |
bool | uniformRowHeights |
whether all items in the treeview have the same height | |
bool | itemsExpandable |
whether the items are expandable by the user. | |
bool | sortingEnabled |
whether sorting is enabled | |
bool | animated |
whether animations are enabled | |
bool | allColumnsShowFocus |
whether items should show keyboard focus using all columns | |
bool | wordWrap |
the item text word-wrapping policy | |
bool | headerHidden |
whether the header is shown or not. | |
bool | expandsOnDoubleClick |
whether the items can be expanded by double-clicking. | |
![]() | |
bool | autoScroll |
whether autoscrolling in drag move events is enabled | |
int | autoScrollMargin |
the size of the area when auto scrolling is triggered | |
EditTriggers | editTriggers |
which actions will initiate item editing | |
bool | tabKeyNavigation |
whether item navigation with tab and backtab is enabled. | |
bool | alternatingRowColors |
whether to draw the background using alternating colors | |
SelectionMode | selectionMode |
which selection mode the view operates in | |
SelectionBehavior | selectionBehavior |
which selection behavior the view uses | |
QSize | iconSize |
the size of items' icons | |
Qt::TextElideMode | textElideMode |
the position of the "..." in elided text. | |
ScrollMode | verticalScrollMode |
how the view scrolls its contents in the vertical direction | |
ScrollMode | horizontalScrollMode |
how the view scrolls its contents in the horizontal direction | |
Private Member Functions | |
void | setModel (QAbstractItemModel *model) override |
\reimp | |
Friends | |
class | QTreeModel |
class | QTreeWidgetItem |
Additional Inherited Members | |
![]() | |
enum | SelectionMode { NoSelection , SingleSelection , MultiSelection , ExtendedSelection , ContiguousSelection } |
This enum indicates how the view responds to user selections: More... | |
enum | SelectionBehavior { SelectItems , SelectRows , SelectColumns } |
\value SelectItems Selecting single items. More... | |
enum | ScrollHint { EnsureVisible , PositionAtTop , PositionAtBottom , PositionAtCenter } |
\value EnsureVisible Scroll to ensure that the item is visible. More... | |
enum | EditTrigger { NoEditTriggers = 0 , CurrentChanged = 1 , DoubleClicked = 2 , SelectedClicked = 4 , EditKeyPressed = 8 , AnyKeyPressed = 16 , AllEditTriggers = 31 } |
This enum describes actions which will initiate item editing. More... | |
enum | ScrollMode { ScrollPerItem , ScrollPerPixel } |
![]() | |
enum | CursorAction { MoveUp , MoveDown , MoveLeft , MoveRight , MoveHome , MoveEnd , MovePageUp , MovePageDown , MoveNext , MovePrevious } |
This enum describes the different ways to navigate between items,. More... | |
enum | State { NoState , DraggingState , DragSelectingState , EditingState , ExpandingState , CollapsingState , AnimatingState } |
Describes the different states the view can be in. More... | |
![]() | |
void | columnResized (int column, int oldSize, int newSize) |
This function is called whenever {column}'s size is changed in the header. | |
void | columnCountChanged (int oldCount, int newCount) |
Informs the tree view that the number of columns in the tree view has changed from oldCount to newCount. | |
void | columnMoved () |
This slot is called whenever a column has been moved. | |
void | reexpand () |
void | rowsRemoved (const QModelIndex &parent, int first, int last) |
void | verticalScrollbarValueChanged (int value) override |
![]() | |
virtual void | dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >()) |
This slot is called when items with the given roles are changed in the model. | |
virtual void | rowsInserted (const QModelIndex &parent, int start, int end) |
This slot is called when rows are inserted. | |
virtual void | rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end) |
This slot is called when rows are about to be removed. | |
virtual void | selectionChanged (const QItemSelection &selected, const QItemSelection &deselected) |
This slot is called when the selection is changed. | |
virtual void | currentChanged (const QModelIndex ¤t, const QModelIndex &previous) |
This slot is called when a new item becomes the current item. | |
virtual void | updateEditorData () |
virtual void | updateEditorGeometries () |
virtual void | updateGeometries () |
virtual void | verticalScrollbarAction (int action) |
virtual void | horizontalScrollbarAction (int action) |
virtual void | verticalScrollbarValueChanged (int value) |
virtual void | horizontalScrollbarValueChanged (int value) |
virtual void | closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint) |
Closes the given editor, and releases it. | |
virtual void | commitData (QWidget *editor) |
Commit the data in the editor to the model. | |
virtual void | editorDestroyed (QObject *editor) |
This function is called when the given editor has been destroyed. | |
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 225 of file qtreewidget.h.
Constructs a tree widget with the given parent.
Definition at line 2570 of file qtreewidget.cpp.
References QAbstractItemView::activated(), QAbstractItemView::clicked(), QTreeView::collapsed(), connect(), QAbstractItemView::currentChanged(), QAbstractItemView::dataChanged(), QAbstractItemView::doubleClicked(), QAbstractItemView::entered(), QTreeView::expanded(), QTreeView::header(), QAbstractItemView::model(), QAbstractItemView::pressed(), QTreeModel, QAbstractItemView::selectionChanged(), QAbstractItemView::selectionModel(), QTreeView::setModel(), QHeaderView::setSectionsClickable(), SIGNAL, and SLOT.
QTreeWidget::~QTreeWidget | ( | ) |
Destroys the tree widget and all its items.
Definition at line 2605 of file qtreewidget.cpp.
void QTreeWidget::addTopLevelItem | ( | QTreeWidgetItem * | item | ) |
Appends the item as a top-level item in the widget.
Definition at line 2699 of file qtreewidget.cpp.
References insertTopLevelItem(), item, and topLevelItemCount.
void QTreeWidget::addTopLevelItems | ( | const QList< QTreeWidgetItem * > & | items | ) |
Appends the list of items as a top-level items in the widget.
Definition at line 2750 of file qtreewidget.cpp.
References insertTopLevelItems(), items, and topLevelItemCount.
|
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 3172 of file qtreewidget.cpp.
References QItemSelectionModel::clear(), d, and QAbstractItemView::selectionModel().
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 2983 of file qtreewidget.cpp.
References QAbstractItemView::closePersistentEditor(), d, and item.
|
slot |
Closes the item.
This causes the tree containing the item's children to be collapsed.
Definition at line 3156 of file qtreewidget.cpp.
References QTreeView::collapse(), d, and item.
int QTreeWidget::columnCount | ( | ) | const |
Definition at line 2615 of file qtreewidget.cpp.
References d.
int QTreeWidget::currentColumn | ( | ) | const |
Definition at line 2840 of file qtreewidget.cpp.
References QModelIndex::column(), and QAbstractItemView::currentIndex().
QTreeWidgetItem * QTreeWidget::currentItem | ( | ) | const |
Returns the current item in the tree widget.
Definition at line 2828 of file qtreewidget.cpp.
References QAbstractItemView::currentIndex(), and d.
|
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 3233 of file qtreewidget.cpp.
References indexFromItem(), QAbstractItemView::model(), and parent.
Referenced by QTreeModel::dropMimeData().
void QTreeWidget::editItem | ( | QTreeWidgetItem * | item, |
int | column = 0 |
||
) |
Starts editing the item in the given column if it is editable.
Definition at line 2956 of file qtreewidget.cpp.
References d, QAbstractItemView::edit(), and item.
|
overrideprotected |
\reimp
Definition at line 3355 of file qtreewidget.cpp.
References d, e, QAbstractItemView::event(), and QEvent::Polish.
|
slot |
Expands the item.
This causes the tree containing the item's children to be expanded.
Definition at line 3143 of file qtreewidget.cpp.
References d, QTreeView::expand(), and item.
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 3069 of file qtreewidget.cpp.
References QList< T >::append(), QList< T >::at(), d, Qt::DisplayRole, i, items, QAbstractItemView::model(), QList< T >::reserve(), QList< T >::size(), and text.
QTreeWidgetItem * QTreeWidget::headerItem | ( | ) | const |
Returns the item used for the tree widget's header.
Definition at line 2761 of file qtreewidget.cpp.
References d.
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 3258 of file qtreewidget.cpp.
Referenced by dropMimeData(), and mimeData().
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 2723 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 2686 of file qtreewidget.cpp.
Referenced by addTopLevelItem().
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 2739 of file qtreewidget.cpp.
Referenced by addTopLevelItems().
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 2644 of file qtreewidget.cpp.
References d.
bool QAbstractItemView::isPersistentEditorOpen | ( | const QModelIndex & | index | ) | const |
Returns whether a persistent editor is open for the item at index index.
Definition at line 182 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 2998 of file qtreewidget.cpp.
References d, QAbstractItemView::isPersistentEditorOpen(), and item.
QTreeWidgetItem * QTreeWidget::itemAbove | ( | const QTreeWidgetItem * | item | ) | const |
Returns the item above the given item.
Definition at line 3088 of file qtreewidget.cpp.
References d, QTreeView::indexAbove(), and item.
|
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 2891 of file qtreewidget.cpp.
References d, and QTreeView::indexAt().
|
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 344 of file qtreewidget.h.
QTreeWidgetItem * QTreeWidget::itemBelow | ( | const QTreeWidgetItem * | item | ) | const |
Returns the item visually below the given item.
Definition at line 3103 of file qtreewidget.cpp.
References d, QTreeView::indexBelow(), and item.
|
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 3269 of file qtreewidget.cpp.
References d.
|
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 3010 of file qtreewidget.cpp.
References d, QAbstractItemView::indexWidget(), and item.
|
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 3198 of file qtreewidget.cpp.
References d, indexFromItem(), item, items, Q_UNLIKELY, and qWarning.
Referenced by QTreeModel::mimeData().
|
protectedvirtual |
Returns a list of MIME types that can be used to describe a list of treewidget items.
Definition at line 3185 of file qtreewidget.cpp.
References QAbstractItemView::model().
void QTreeWidget::openPersistentEditor | ( | QTreeWidgetItem * | item, |
int | column = 0 |
||
) |
Opens a persistent editor for the item in the given column.
Definition at line 2968 of file qtreewidget.cpp.
References d, item, and QAbstractItemView::openPersistentEditor().
|
inline |
Removes the widget set in the given item in the given column.
Definition at line 341 of file qtreewidget.h.
References item.
|
slot |
Ensures that the item is visible, scrolling the view if necessary using the specified hint.
Definition at line 3131 of file qtreewidget.cpp.
References d, hint(), item, and QTreeView::scrollTo().
QList< QTreeWidgetItem * > QTreeWidget::selectedItems | ( | ) | const |
Returns a list of all selected non-hidden items.
Definition at line 3050 of file qtreewidget.cpp.
References QList< T >::append(), d, QDuplicateTracker< T, Prealloc >::hasSeen(), item, items, QList< T >::reserve(), QItemSelectionModel::selectedIndexes, QAbstractItemView::selectionModel(), and QList< T >::size().
void QTreeWidget::setColumnCount | ( | int | columns | ) |
Definition at line 2625 of file qtreewidget.cpp.
References d.
Referenced by setHeaderLabels(), MainWindow::showList(), and qfontdatabase_snippets::wrapper().
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 2853 of file qtreewidget.cpp.
References item, and setCurrentItem().
Referenced by setCurrentItem().
void QTreeWidget::setCurrentItem | ( | QTreeWidgetItem * | item, |
int | column | ||
) |
Definition at line 2864 of file qtreewidget.cpp.
References d, item, and QAbstractItemView::setCurrentIndex().
void QTreeWidget::setCurrentItem | ( | QTreeWidgetItem * | item, |
int | column, | ||
QItemSelectionModel::SelectionFlags | command | ||
) |
Definition at line 2877 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 2776 of file qtreewidget.cpp.
References columnCount, d, Qt::Horizontal, and item.
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 2806 of file qtreewidget.cpp.
References columnCount, d, i, item, and setColumnCount().
Referenced by MainWindow::showList(), and qfontdatabase_snippets::wrapper().
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 3039 of file qtreewidget.cpp.
References d, item, QAbstractItemView::setIndexWidget(), and widget.
|
overrideprivatevirtual |
\reimp
Reimplemented from QTreeView.
Definition at line 3347 of file qtreewidget.cpp.
References Q_ASSERT.
|
overridevirtual |
\reimp
Reimplemented from QTreeView.
Definition at line 3116 of file qtreewidget.cpp.
References d, QList< T >::isEmpty(), QItemSelectionModel::selection, QAbstractItemView::selectionModel(), and QTreeView::setSelectionModel().
int QTreeWidget::sortColumn | ( | ) | const |
Returns the column used to sort the contents of the widget.
Definition at line 2930 of file qtreewidget.cpp.
References d, QTreeView::header(), and QHeaderView::sortIndicatorSection().
Referenced by QTreeWidgetItem::operator<().
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 2945 of file qtreewidget.cpp.
References d, QTreeView::header(), and QHeaderView::setSortIndicator().
|
protectedvirtual |
Returns the drop actions supported by this view.
Definition at line 3246 of file qtreewidget.cpp.
References QAbstractItemView::model(), and Qt::MoveAction.
Referenced by QTreeModel::supportedDropActions().
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 2711 of file qtreewidget.cpp.
References d.
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 2657 of file qtreewidget.cpp.
References d.
int QTreeWidget::topLevelItemCount | ( | ) | const |
Definition at line 2672 of file qtreewidget.cpp.
References d.
QRect QTreeWidget::visualItemRect | ( | const QTreeWidgetItem * | item | ) | const |
Returns the rectangle on the viewport occupied by the item at item.
Definition at line 2910 of file qtreewidget.cpp.
References base, d, QTreeView::header(), item, QHeaderView::logicalIndexAt(), and QTreeView::visualRect().
|
friend |
Definition at line 231 of file qtreewidget.h.
Referenced by QTreeWidget().
|
friend |
Definition at line 232 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 187 of file qtreewidget.h.
Referenced by setHeaderItem(), and setHeaderLabels().
|
read |
the number of top-level items
By default, this property has a value of 0.
Definition at line 187 of file qtreewidget.h.
Referenced by addTopLevelItem(), and addTopLevelItems().