Home · All Classes · Modules |
The QTreeView class provides a default model/view implementation of a tree view. More...
Inherits QAbstractItemView.
Inherited by QHelpContentWidget and QTreeWidget.
The QTreeView class provides a default model/view implementation of a tree view.
A QTreeView implements a tree representation of items from a model. This class is used to provide standard hierarchical lists that were previously provided by the QListView class, but using the more flexible approach provided by Qt's model/view architecture.
The QTreeView class is one of the Model/View Classes and is part of Qt's model/view framework.
QTreeView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.
It is simple to construct a tree view displaying data from a model. In the following example, the contents of a directory are supplied by a QFileSystemModel and displayed as a tree:
QFileSystemModel *model = new QFileSystemModel; model->setRootPath(QDir.currentPath()); QTreeView *tree = new QTreeView(splitter); tree->setModel(model);
The model/view architecture ensures that the contents of the tree view are updated as the model changes.
Items that have children can be in an expanded (children are visible) or collapsed (children are hidden) state. When this state changes a collapsed() or expanded() signal is emitted with the model index of the relevant item.
The amount of indentation used to indicate levels of hierarchy is controlled by the indentation property.
Headers in tree views are constructed using the QHeaderView class and can be hidden using header()->hide(). Note that each header is configured with its stretchLastSection property set to true, ensuring that the view does not waste any of the space assigned to it for its header. If this value is set to true, this property will override the resize mode set on the last section in the header.
QTreeView supports a set of key bindings that enable the user to navigate in the view and interact with the contents of items:
Key | Action |
---|---|
Up | Moves the cursor to the item in the same column on the previous row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the last row of the sibling that precedes the parent. |
Down | Moves the cursor to the item in the same column on the next row. If the parent of the current item has no more rows to navigate to, the cursor moves to the relevant item in the first row of the sibling that follows the parent. |
Left | Hides the children of the current item (if present) by collapsing a branch. |
Minus | Same as LeftArrow. |
Right | Reveals the children of the current item (if present) by expanding a branch. |
Plus | Same as RightArrow. |
Asterisk | Expands all children of the current item (if present). |
PageUp | Moves the cursor up one page. |
PageDown | Moves the cursor down one page. |
Home | Moves the cursor to an item in the same column of the first row of the first top-level item in the model. |
End | Moves the cursor to an item in the same column of the last row of the last top-level item in the model. |
F2 | In editable models, this opens the current item for editing. The Escape key can be used to cancel the editing process and revert any changes to the data displayed. |
A Windows XP style tree view. | A Macintosh style tree view. | A Plastique style tree view. |
It is possible to give the view hints about the data it is handling in order to improve its performance when displaying large numbers of items. One approach that can be taken for views that are intended to display items with equal heights is to set the uniformRowHeights property to true.
The parent argument, if not None, causes self to be owned by Qt instead of PyQt.
Constructs a tree view with a parent to represent a model's data. Use setModel() to set the model.
See also QAbstractItemModel.
This method is also a Qt slot with the C++ signature void collapse(const QModelIndex&).
Collapses the model item specified by the index.
See also collapsed().
This method is also a Qt slot with the C++ signature void collapseAll().
Collapses all expanded items.
This function was introduced in Qt 4.2.
See also expandAll(), expand(), collapse(), and setExpanded().
Returns the column in the tree view whose header covers the x coordinate given.
This method is also a Qt slot with the C++ signature void columnCountChanged(int,int).
Informs the tree view that the number of columns in the tree view has changed from oldCount to newCount.
This method is also a Qt slot with the C++ signature void columnMoved().
This slot is called whenever a column has been moved.
This method is also a Qt slot with the C++ signature void columnResized(int,int,int).
This function is called whenever column's size is changed in the header. oldSize and newSize give the previous size and the new size in pixels.
See also setColumnWidth().
Returns the horizontal position of the column in the viewport.
Returns the width of the column.
See also resizeColumnToContents() and setColumnWidth().
Reimplemented from QAbstractItemView.currentChanged().
This method is also a Qt slot with the C++ signature void dataChanged(const QModelIndex&,const QModelIndex&).
Reimplemented from QAbstractItemView.dataChanged().
Reimplemented from QWidget.dragMoveEvent().
Draws the branches in the tree view on the same row as the model item index, using the painter given. The branches are drawn in the rectangle specified by rect.
Draws the row in the tree view that contains the model item index, using the painter given. The option control how the item is displayed.
See also setAlternatingRowColors().
Draws the part of the tree intersecting the given region using the specified painter.
This function was introduced in Qt 4.2.
See also paintEvent().
This method is also a Qt slot with the C++ signature void expand(const QModelIndex&).
Expands the model item specified by the index.
See also expanded().
This method is also a Qt slot with the C++ signature void expandAll().
Expands all expandable items.
Warning: if the model contains a large number of items, this function will take some time to execute.
This function was introduced in Qt 4.2.
See also collapseAll(), expand(), collapse(), and setExpanded().
This method is also a Qt slot with the C++ signature void expandToDepth(int).
Expands all expandable items to the given depth.
This function was introduced in Qt 4.3.
See also expandAll(), collapseAll(), expand(), collapse(), and setExpanded().
Returns the header for the tree view.
See also setHeader() and QAbstractItemModel.headerData().
This method is also a Qt slot with the C++ signature void hideColumn(int).
Hides the column given.
Note: This function should only be called after the model has been initialized, as the view needs to know the number of columns in order to hide column.
See also showColumn() and setColumnHidden().
Reimplemented from QAbstractItemView.horizontalOffset().
Returns the horizontal offset of the items in the treeview.
Note that the tree view uses the horizontal header section positions to determine the positions of columns in the view.
See also verticalOffset().
Returns the model index of the item above index.
Reimplemented from QAbstractItemView.indexAt().
Returns the model index of the item below index.
Returns the size hint for the row indicated by index.
See also sizeHintForColumn() and uniformRowHeights().
Returns true if the column is hidden; otherwise returns false.
See also hideColumn() and isRowHidden().
Returns true if the model item index is expanded; otherwise returns false.
See also expand(), expanded(), and setExpanded().
Returns true if the item in first column in the given row of the parent is spanning all the columns; otherwise returns false.
This function was introduced in Qt 4.3.
See also setFirstColumnSpanned().
Reimplemented from QAbstractItemView.isIndexHidden().
Returns true if the item in the given row of the parent is hidden; otherwise returns false.
See also setRowHidden() and isColumnHidden().
Reimplemented from QAbstractItemView.keyboardSearch().
Reimplemented from QWidget.keyPressEvent().
Reimplemented from QWidget.mouseDoubleClickEvent().
Reimplemented from QWidget.mouseMoveEvent().
Reimplemented from QWidget.mousePressEvent().
Reimplemented from QWidget.mouseReleaseEvent().
Reimplemented from QAbstractItemView.moveCursor().
Move the cursor in the way described by cursorAction, using the information provided by the button modifiers.
Reimplemented from QWidget.paintEvent().
This method is also a Qt slot with the C++ signature void reexpand().
Reimplemented from QAbstractItemView.reset().
This method is also a Qt slot with the C++ signature void resizeColumnToContents(int).
Resizes the column given to the size of its contents.
See also columnWidth() and setColumnWidth().
Returns the height of the row indicated by the given index.
This function was introduced in Qt 4.3.
See also indexRowSizeHint().
Reimplemented from QAbstractItemView.rowsAboutToBeRemoved().
Informs the view that the rows from the start row to the end row inclusive are about to removed from the given parent model item.
Reimplemented from QAbstractItemView.rowsInserted().
Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item.
This method is also a Qt slot with the C++ signature void rowsRemoved(const QModelIndex&,int,int).
Informs the view that the rows from the start row to the end row inclusive have been removed from the given parent model item.
This function was introduced in Qt 4.1.
Reimplemented from QAbstractScrollArea.scrollContentsBy().
Scrolls the contents of the tree view by (dx, dy).
Reimplemented from QAbstractItemView.scrollTo().
Scroll the contents of the tree view until the given model item index is visible. The hint parameter specifies more precisely where the item should be located after the operation. If any of the parents of the model item are collapsed, they will be expanded to ensure that the model item is visible.
This method is also a Qt slot with the C++ signature void selectAll().
Reimplemented from QAbstractItemView.selectAll().
Reimplemented from QAbstractItemView.selectedIndexes().
Reimplemented from QAbstractItemView.selectionChanged().
If hide is true the column is hidden, otherwise the column is shown.
See also isColumnHidden(), hideColumn(), and setRowHidden().
Sets the width of the given column to the width specified.
This function was introduced in Qt 4.2.
See also columnWidth() and resizeColumnToContents().
Sets the item referred to by index to either collapse or expanded, depending on the value of expanded.
See also expanded(), expand(), and isExpanded().
If span is true the item in the first column in the row with the given parent is set to span all columns, otherwise all items on the row are shown.
This function was introduced in Qt 4.3.
See also isFirstColumnSpanned().
The header argument has it's ownership transferred to Qt.
Sets the header for the tree view, to the given header.
The view takes ownership over the given header and deletes it when a new header is set.
See also QAbstractItemModel.headerData().
Reimplemented from QAbstractItemView.setModel().
Reimplemented from QAbstractItemView.setRootIndex().
If hide is true the row with the given parent is hidden, otherwise the row is shown.
See also isRowHidden() and setColumnHidden().
Reimplemented from QAbstractItemView.setSelection().
Applies the selection command to the items in or touched by the rectangle, rect.
See also selectionCommand().
Reimplemented from QAbstractItemView.setSelectionModel().
This method is also a Qt slot with the C++ signature void showColumn(int).
Shows the given column in the tree view.
See also hideColumn() and setColumnHidden().
Reimplemented from QAbstractItemView.sizeHintForColumn().
Returns the size hint for the column's width or -1 if there is no model.
If you need to set the width of a given column to a fixed value, call QHeaderView.resizeSection() on the view's header.
If you reimplement this function in a subclass, note that the value you return is only used when resizeColumnToContents() is called. In that case, if a larger column width is required by either the view's header or the item delegate, that width will be used instead.
See also QWidget.sizeHint and header().
This method is also a Qt slot with the C++ signature void sortByColumn(int).
Sets the model up for sorting by the values in the given column and order.
column may be -1, in which case no sort indicator will be shown and the model will return to its natural, unsorted order. Note that not all models support this and may even crash in this case.
This function was introduced in Qt 4.2.
See also sortingEnabled.
Reimplemented from QObject.timerEvent().
Reimplemented from QAbstractItemView.updateGeometries().
Reimplemented from QAbstractItemView.verticalOffset().
Returns the vertical offset of the items in the tree view.
See also horizontalOffset().
Reimplemented from QAbstractScrollArea.viewportEvent().
Reimplemented from QAbstractItemView.visualRect().
Returns the rectangle on the viewport occupied by the item at index. If the index is not visible or explicitly hidden, the returned rectangle is invalid.
Reimplemented from QAbstractItemView.visualRegionForSelection().
Returns the rectangle from the viewport of the items in the given selection.
Since 4.7, the returned region only contains rectangles intersecting (or included in) the viewport.
This is the default overload of this signal.
This signal is emitted when the item specified by index is collapsed.
This is the default overload of this signal.
This signal is emitted when the item specified by index is expanded.
See also setExpanded().
PyQt 4.9.4 for Windows | Copyright © Riverbank Computing Ltd and Nokia 2012 | Qt 4.8.2 |