Qt:Документация 4.3.2/qtreeview

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QTreeView Class Reference
[модуль QtGui ]

The QTreeView class provides a default model/view implementation of a tree view. More...

 #include <QTreeView>

Inherits QAbstractItemView.

Inherited by QTreeWidget.

[править] Свойства

  • 14 свойства унаследованных от QAbstractItemView
  • 2 свойства унаследованных от QAbstractScrollArea
  • 6 свойства унаследованных от QFrame
  • 56 свойства унаследованных от QWidget
  • 1 свойство унаследованное от QObject

[править] Открытые функции

  • 52 открытых функций унаследованных от QAbstractItemView
  • 15 открытых функций унаследованных от QAbstractScrollArea
  • 13 открытых функций унаследованных от QFrame
  • 201 открытых функций унаследованных от QWidget
  • 29 открытых функций унаследованных от QObject
  • 12 открытых функций унаследованных от QPaintDevice

[править] Открытые слоты

  • 9 открытых слотов унаследованных от QAbstractItemView
  • 19 открытых слотов унаследованных от QWidget
  • 1 открытый слот унаследованный от QObject

[править] Сигналы

  • 6 сигнала унаследованных от QAbstractItemView
  • 1 сигнал унаследованный от QWidget
  • 1 сигнал унаследованный от QObject

[править] Защищенные функции

  • 33 защищенных функций унаследованных от QAbstractItemView
  • 16 защищенных функций унаследованных от QAbstractScrollArea
  • 38 защищенных функций унаследованных от QWidget
  • 7 защищенных функций унаследованных от QObject
  • 1 защищенная функция унаследованна от QPaintDevice

[править] Защищенные слоты

  • 8 защищенных слотов унаследованных от QAbstractItemView
  • 1 защищенный слот унаследованный от QAbstractScrollArea
  • 1 защищенный слот унаследованный от QWidget

[править] Дополнительные унаследованные члены

  • 4 статических открытых члена унаследованных от QWidget
  • 5 статических открытых члена унаследованных от QObject

[править] Подробное описание

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:

     QDirModel *model = new QDirModel;
     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.

[править] Key Bindings

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
UpArrow 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.
DownArrow 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.
LeftArrow Hides the children of the current item (if present) by collapsing a branch.
Minus Same as LeftArrow.
RightArrow 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.


center center center
A Windows XP style tree view. A Macintosh style tree view. A Plastique style tree view.

[править] Improving Performance

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.


[править] Описание свойств

[править]
allColumnsShowFocus : bool

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.

Функции доступа:

  • bool allColumnsShowFocus () const
  • void setAllColumnsShowFocus ( bool enable )

[править]
animated : bool

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.

This property was introduced in Qt Qt 4.2.

Функции доступа:

  • bool isAnimated () const
  • void setAnimated ( bool enable )

[править]
autoExpandDelay : int

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.

This property was introduced in Qt 4.3.

Функции доступа:

  • int autoExpandDelay () const
  • void setAutoExpandDelay ( int delay )

[править]
indentation : int

This property holds indentation of the items in the tree view.

This property holds the indentation measured in pixels of the items for each level in the tree view. For top-level items, the indentation specifies the horizontal distance from the viewport edge to the items in the first column; for child items, it specifies their indentation from their parent items.

Функции доступа:

  • int indentation () const
  • void setIndentation ( int i )

[править]
itemsExpandable : bool

This property holds whether the items are expandable by the user.

This property holds whether the user can expand and collapse items interactively.

Функции доступа:

  • bool itemsExpandable () const
  • void setItemsExpandable ( bool enable )

[править]
rootIsDecorated : bool

This property holds whether to show controls for expanding and collapsing top-level items.

Items with children are typically shown with controls to expand and collapse them, allowing their children to be shown or hidden. If this property is false, these controls are not shown for top-level items. This can be used to make a single level tree structure appear like a simple list of items.

By default, this property is true.

Функции доступа:

  • bool rootIsDecorated () const
  • void setRootIsDecorated ( bool show )

[править]
sortingEnabled : bool

This property holds whether sorting is enabled.

If this property is true, sorting is enabled for the tree; if the property is false, sorting is not enabled. The default value is false.

This property was introduced in Qt Qt 4.2.

Функции доступа:

  • bool isSortingEnabled () const
  • void setSortingEnabled ( bool enable )

See also sortByColumn().

[править]
uniformRowHeights : bool

This property holds whether all items in the treeview have the same height.

This property should only be set to true if it is guaranteed that all items in the view has the same height. This enables the view to do some optimizations.

Функции доступа:

  • bool uniformRowHeights () const
  • void setUniformRowHeights ( bool uniform )

[править]
wordWrap : bool

This property holds the item text word-wrapping policy.

If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is false by default.

This property was introduced in Qt 4.3.

Функции доступа:

  • bool wordWrap () const
  • void setWordWrap ( bool on )

[править] Описание функций-членов

[править]
QTreeView::QTreeView ( QWidget * parent = 0 )

Constructs a table view with a parent to represent a model's data. Use setModel() to set the model.

See also QAbstractItemModel.

[править]
QTreeView::~QTreeView ()

Destroys the tree view.

[править]
void QTreeView::collapse ( const QModelIndex & index ) [slot]

Collapses the model item specified by the index.

See also collapsed().

[править]
void QTreeView::collapseAll () [slot]

Collapses all expanded items.

This function was introduced in Qt 4.2.

See also expandAll(), expand(), collapse(), and setExpanded().

[править]
void QTreeView::collapsed ( const QModelIndex & index ) [signal]

This signal is emitted when the item specified by index is collapsed.

[править]
int QTreeView::columnAt ( int x ) const

Returns the column in the tree view whose header covers the x coordinate given.

[править]
void QTreeView::columnCountChanged ( int oldCount, int newCount ) [protected slot]

Informs the tree view that the number of columns in the tree view has changed from oldCount to newCount.

[править]
void QTreeView::columnMoved () [protected slot]

This slot is called whenever a column has been moved.

[править]
void QTreeView::columnResized ( int column, int oldSize, int newSize ) [protected slot]

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().

[править]
int QTreeView::columnViewportPosition ( int column ) const

Returns the horizontal position of the column in the viewport.

[править]
int QTreeView::columnWidth ( int column ) const

Returns the width of the column.

See also resizeColumnToContents() and setColumnWidth().

[править]
void QTreeView::drawBranches ( QPainter * painter, const QRect & rect, const QModelIndex & index ) const [virtual protected]

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.

[править]
void QTreeView::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const [virtual protected]

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().

[править]
void QTreeView::drawTree ( QPainter * painter, const QRegion & region ) const [protected]

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().

[править]
void QTreeView::expand ( const QModelIndex & index ) [slot]

Expands the model item specified by the index.

See also expanded().

[править]
void QTreeView::expandAll () [slot]

Expands all expandable items.

Warning: if the model contains a large number of items, this function will be take time to execute.

This function was introduced in Qt 4.2.

See also collapseAll(), expand(), collapse(), and setExpanded().

[править]
void QTreeView::expandToDepth ( int depth ) [slot]

Expands all expandable items to the given depth.

This function was introduced in Qt 4.3.

See also expandAll(), collapseAll(), expand(), collapse(), and setExpanded().

[править]
void QTreeView::expanded ( const QModelIndex & index ) [signal]

This signal is emitted when the item specified by index is expanded.

See also setExpanded().

[править] QHeaderView * QTreeView::header () const

Returns the header for the tree view.

See also setHeader() and QAbstractItemModel::headerData().

[править]
void QTreeView::hideColumn ( int column ) [slot]

Hides the column given.

See also showColumn() and setColumnHidden().

[править]
int QTreeView::horizontalOffset () const [virtual protected]

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.

Reimplemented from QAbstractItemView.

See also verticalOffset().

[править]
QModelIndex QTreeView::indexAbove ( const QModelIndex & index ) const

Returns the model index of the item above index.

[править]
QModelIndex QTreeView::indexBelow ( const QModelIndex & index ) const

Returns the model index of the item below index.

[править]
int QTreeView::indexRowSizeHint ( const QModelIndex & index ) const [protected]

Returns the size hint for the row indicated by index.

See also sizeHintForColumn() and uniformRowHeights().

[править]
bool QTreeView::isColumnHidden ( int column ) const

Returns true if the column is hidden; otherwise returns false.

See also hideColumn() and isRowHidden().

[править]
bool QTreeView::isExpanded ( const QModelIndex & index ) const

Returns true if the model item index is expanded; otherwise returns false.

See also expand(), expanded(), and setExpanded().

[править]
bool QTreeView::isFirstColumnSpanned ( int row, const QModelIndex & parent ) const

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().

[править]
bool QTreeView::isRowHidden ( int row, const QModelIndex & parent ) const

Returns true if the item in the given row of the parent is hidden; otherwise returns false.

See also setRowHidden() and isColumnHidden().

[править]
QModelIndex QTreeView::moveCursor ( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) [virtual protected]

Move the cursor in the way described by cursorAction, using the information provided by the button modifiers.

Reimplemented from QAbstractItemView.

[править]
void QTreeView::resizeColumnToContents ( int column ) [slot]

Resizes the column given to the size of its contents.

See also columnWidth() and setColumnWidth().

[править]
int QTreeView::rowHeight ( const QModelIndex & index ) const [protected]

Returns the height of the row indicated by the given index.

This function was introduced in Qt 4.3.

See also indexRowSizeHint().

[править]
void QTreeView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end ) [virtual protected]

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.

[править]
void QTreeView::rowsInserted ( const QModelIndex & parent, int start, int end ) [virtual protected]

Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item.

Reimplemented from QAbstractItemView.

[править]
void QTreeView::rowsRemoved ( const QModelIndex & parent, int start, int end ) [protected slot]

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.

[править]
void QTreeView::scrollContentsBy ( int dx, int dy ) [virtual protected]

Scrolls the contents of the tree view by (dx, dy).

Reimplemented from QAbstractScrollArea.

[править]
void QTreeView::scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible ) [virtual]

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.

Reimplemented from QAbstractItemView.

[править]
void QTreeView::selectAll () [virtual slot]

Selects all the items in the underlying model.

Reimplemented from QAbstractItemView.

[править]
void QTreeView::setColumnHidden ( int column, bool hide )

If hide is true the column is hidden, otherwise the column is shown.

See also isColumnHidden(), hideColumn(), and setRowHidden().

[править]
void QTreeView::setColumnWidth ( int column, int width )

Sets the width of the given column to the width specified.

This function was introduced in Qt 4.2.

See also columnWidth() and resizeColumnToContents().

[править]
void QTreeView::setExpanded ( const QModelIndex & index, bool expanded )

Sets the item referred to by index to either collapse or expanded, depending on the value of expanded.

See also expanded(), expand(), and isExpanded().

[править]
void QTreeView::setFirstColumnSpanned ( int row, const QModelIndex & parent, bool span )

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().

[править]
void QTreeView::setHeader ( QHeaderView * header )

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().

[править]
void QTreeView::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.

See also isRowHidden() and setColumnHidden().

[править]
void QTreeView::setSelection ( const QRect & rect, QItemSelectionModel::SelectionFlags command ) [virtual protected]

Applies the selection command to the items in or touched by the rectangle, rect.

Reimplemented from QAbstractItemView.

See also selectionCommand().

[править]
void QTreeView::showColumn ( int column ) [slot]

Shows the given column in the tree view.

See also hideColumn() and setColumnHidden().

[править]
int QTreeView::sizeHintForColumn ( int column ) const [virtual protected]

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.

Reimplemented from QAbstractItemView.

See also QWidget::sizeHint and header().

[править]
void QTreeView::sortByColumn ( int column, Qt::SortOrder order )

Sorts the model by the values in the given column in the given order.

This function was introduced in Qt 4.2.

See also sortingEnabled.

[править]
int QTreeView::verticalOffset () const [virtual protected]

Returns the vertical offset of the items in the tree view.

Reimplemented from QAbstractItemView.

See also horizontalOffset().

[править]
QRect QTreeView::visualRect ( const QModelIndex & index ) const [virtual]

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.

[править]
QRegion QTreeView::visualRegionForSelection ( const QItemSelection & selection ) const [virtual protected]

Returns the rectangle from the viewport of the items in the given selection.

Reimplemented from QAbstractItemView.

Если у вас есть перевод, то его можно выложить в Перевод Qt документации на русский язык...



Copyright © 2007 Trolltech Trademarks
Qt 4.3.2