QTreeView Class Reference |
|
|
QTreeView ( QWidget * parent = 0 ) | |
~QTreeView () | |
bool | allColumnsShowFocus () const |
int | autoExpandDelay () const |
int | columnAt ( int x ) const |
int | columnViewportPosition ( int column ) const |
int | columnWidth ( int column ) const |
bool | expandsOnDoubleClick () const |
QHeaderView * | header () const |
int | indentation () const |
QModelIndex | indexAbove ( const QModelIndex & index ) const |
QModelIndex | indexBelow ( const QModelIndex & index ) const |
bool | isAnimated () const |
bool | isColumnHidden ( int column ) const |
bool | isExpanded ( const QModelIndex & index ) const |
bool | isFirstColumnSpanned ( int row, const QModelIndex & parent ) const |
bool | isHeaderHidden () const |
bool | isRowHidden ( int row, const QModelIndex & parent ) const |
bool | isSortingEnabled () const |
bool | itemsExpandable () const |
bool | rootIsDecorated () const |
void | setAllColumnsShowFocus ( bool enable ) |
void | setAnimated ( bool enable ) |
void | setAutoExpandDelay ( int delay ) |
void | setColumnHidden ( int column, bool hide ) |
void | setColumnWidth ( int column, int width ) |
void | setExpanded ( const QModelIndex & index, bool expanded ) |
void | setExpandsOnDoubleClick ( bool enable ) |
void | setFirstColumnSpanned ( int row, const QModelIndex & parent, bool span ) |
void | setHeader ( QHeaderView * header ) |
void | setHeaderHidden ( bool hide ) |
void | setIndentation ( int i ) |
void | setItemsExpandable ( bool enable ) |
void | setRootIsDecorated ( bool show ) |
void | setRowHidden ( int row, const QModelIndex & parent, bool hide ) |
void | setSortingEnabled ( bool enable ) |
void | setUniformRowHeights ( bool uniform ) |
void | setWordWrap ( bool on ) |
void | sortByColumn ( int column, Qt::SortOrder order ) |
bool | uniformRowHeights () const |
bool | wordWrap () const |
virtual void | dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) |
virtual QModelIndex | indexAt ( const QPoint & point ) const |
virtual void | keyboardSearch ( const QString & search ) |
virtual void | reset () |
virtual void | scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible ) |
virtual void | selectAll () |
virtual void | setModel ( QAbstractItemModel * model ) |
virtual void | setRootIndex ( const QModelIndex & index ) |
virtual void | setSelectionModel ( QItemSelectionModel * selectionModel ) |
virtual QRect | visualRect ( const QModelIndex & index ) const |
void | collapse ( const QModelIndex & index ) |
void | collapseAll () |
void | expand ( const QModelIndex & index ) |
void | expandAll () |
void | expandToDepth ( int depth ) |
void | hideColumn ( int column ) |
void | resizeColumnToContents ( int column ) |
void | showColumn ( int column ) |
void | collapsed ( const QModelIndex & index ) |
void | expanded ( const QModelIndex & index ) |
virtual void | drawBranches ( QPainter * painter, const QRect & rect, const QModelIndex & index ) const |
virtual void | drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const |
void | drawTree ( QPainter * painter, const QRegion & region ) const |
int | indexRowSizeHint ( const QModelIndex & index ) const |
int | rowHeight ( const QModelIndex & index ) const |
virtual void | currentChanged ( const QModelIndex & current, const QModelIndex & previous ) |
virtual void | dragMoveEvent ( QDragMoveEvent * event ) |
virtual int | horizontalOffset () const |
virtual bool | isIndexHidden ( const QModelIndex & index ) const |
virtual void | keyPressEvent ( QKeyEvent * event ) |
virtual void | mouseDoubleClickEvent ( QMouseEvent * event ) |
virtual void | mouseMoveEvent ( QMouseEvent * event ) |
virtual void | mousePressEvent ( QMouseEvent * event ) |
virtual void | mouseReleaseEvent ( QMouseEvent * event ) |
virtual QModelIndex | moveCursor ( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) |
virtual void | paintEvent ( QPaintEvent * event ) |
virtual void | rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end ) |
virtual void | rowsInserted ( const QModelIndex & parent, int start, int end ) |
virtual void | scrollContentsBy ( int dx, int dy ) |
virtual QModelIndexList | selectedIndexes () const |
virtual void | selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) |
virtual void | setSelection ( const QRect & rect, QItemSelectionModel::SelectionFlags command ) |
virtual int | sizeHintForColumn ( int column ) const |
virtual void | timerEvent ( QTimerEvent * event ) |
virtual void | updateGeometries () |
virtual int | verticalOffset () const |
virtual bool | viewportEvent ( QEvent * event ) |
virtual QRegion | visualRegionForSelection ( const QItemSelection & selection ) const |
void | columnCountChanged ( int oldCount, int newCount ) |
void | columnMoved () |
void | columnResized ( int column, int oldSize, int newSize ) |
void | rowsRemoved ( const QModelIndex & parent, int start, int end ) |
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 QDirModel 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.
See also QListView, QTreeWidget, View Classes, QAbstractItemModel, QAbstractItemView, and Dir View Example.
This property holds whether items should show keyboard focus using all columns.
If this property is true all columns will show focus, otherwise only one column will show focus.
The default is false.
This property was introduced in Qt 4.2.
Access functions:
bool | allColumnsShowFocus () const |
void | setAllColumnsShowFocus ( bool enable ) |
This property holds whether animations are enabled.
If this property is true the treeview will animate expandsion and collasping of branches. If this property is false, the treeview will expand or collapse branches immediately without showing the animation.
By default, this property is false.
This property was introduced in Qt 4.2.
Access functions:
bool | isAnimated () const |
void | setAnimated ( bool enable ) |
This property holds the delay time before items in a tree are opened during a drag and drop operation.
This property holds the amount of time in milliseconds that the user must wait over a node before that node will automatically open or close. If the time is set to less then 0 then it will not be activated.
By default, this property has a value of -1, meaning that auto-expansion is disabled.
This property was introduced in Qt 4.3.
Access functions:
int | autoExpandDelay () const |
void | setAutoExpandDelay ( int delay ) |
This property holds whether the items can be expanded by double-clicking.
This property holds whether the user can expand and collapse items by double-clicking. The default value is true.
This property was introduced in Qt 4.4.
Access functions:
bool | expandsOnDoubleClick () const |
void | setExpandsOnDoubleClick ( bool enable ) |
See also itemsExpandable.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.6-snapshot | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com