QTreeView Class ReferenceThe QTreeView class provides a default model/view implementation of a tree view. Далее... #include <QTreeView> Унаследован от: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. Key BindingsQTreeView supports a set of key bindings that enable the user to navigate in the view and interact with the contents 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 : boolThis 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. По умолчанию равно false. Это свойство было введено в Qt 4.2. Функции доступа:
animated : boolДанное свойство указывает, разрешены ли анимации. 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. По умолчанию это свойство равно false. Это свойство было введено в Qt 4.2. Функции доступа:
autoExpandDelay : intThis 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. Это свойство было введено в Qt 4.3. Функции доступа:
expandsOnDoubleClick : boolThis 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. Значение по умолчанию равно true. Это свойство было введено в Qt 4.4. Функции доступа:
See also itemsExpandable. headerHidden : boolThis property holds whether the header is shown or not. If this property is true, the header is not shown otherwise it is. Значение по умолчанию равно false. Это свойство было введено в Qt 4.4. Функции доступа:
See also header(). indentation : intThis 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. By default, this property has a value of 20. Функции доступа:
itemsExpandable : boolThis property holds whether the items are expandable by the user. This property holds whether the user can expand and collapse items interactively. По умолчанию это свойство равно true. Функции доступа:
rootIsDecorated : boolThis 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. По умолчанию это свойство равно true. Функции доступа:
sortingEnabled : boolThis 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. Значение по умолчанию равно false. Note: In order to avoid performance issues, it is recommended that sorting is enabled after inserting the items into the tree. Alternatively, you could also insert the items into a list before inserting the items into the tree. Это свойство было введено в Qt 4.2. Функции доступа:
See also sortByColumn(). uniformRowHeights : boolThis 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. Это позволяет представлению производить некоторую оптимизацию. The height is obtained from the first item in the view. It is updated when the data changes on that item. По умолчанию это свойство равно false. Функции доступа:
wordWrap : boolЭто свойство отвечает за политику переноса текста в элементах. Если оно равно true, происходит перенос по непосредственному окончанию слов; в противном случае переноса нет вообще. Свойство равно false по умолчанию. Note that even if wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current textElideMode. Это свойство было введено в Qt 4.3. Функции доступа:
Описание функций-членовQTreeView::QTreeView ( QWidget * parent = 0 )Constructs a tree view with a parent to represent a model's data. Use setModel() to set the model. Смотрите также 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. Эта функция была введена в 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 ) constReturns 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 ) constReturns the horizontal position of the column in the viewport. int QTreeView::columnWidth ( int column ) constReturns the width of the column. See also resizeColumnToContents() and setColumnWidth(). void QTreeView::currentChanged ( const QModelIndex & current, const QModelIndex & previous ) [virtual protected]Переопределено из QAbstractItemView::currentChanged(). void QTreeView::dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) [virtual]Переопределено из QAbstractItemView::dataChanged(). void QTreeView::dragMoveEvent ( QDragMoveEvent * event ) [virtual protected]Переопределено из QWidget::dragMoveEvent(). 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. Эта функция была введена в Qt 4.2. Смотрите также 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 take some time to execute. Эта функция была введена в Qt 4.2. See also collapseAll(), expand(), collapse(), and setExpanded(). void QTreeView::expandToDepth ( int depth ) [slot]Expands all expandable items to the given depth. Эта функция была введена в 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 () constReturns the header for the tree view. See also setHeader() and QAbstractItemModel::headerData(). void QTreeView::hideColumn ( int column ) [slot]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(). int QTreeView::horizontalOffset () const [virtual protected]Переопределено из 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(). QModelIndex QTreeView::indexAbove ( const QModelIndex & index ) constReturns the model index of the item above index. QModelIndex QTreeView::indexAt ( const QPoint & point ) const [virtual]Переопределено из QAbstractItemView::indexAt(). QModelIndex QTreeView::indexBelow ( const QModelIndex & index ) constReturns 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 ) constReturns true if the column is hidden; otherwise returns false. Смотрите также hideColumn() и isRowHidden(). bool QTreeView::isExpanded ( const QModelIndex & index ) constReturns 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 ) constReturns true if the item in first column in the given row of the parent is spanning all the columns; otherwise returns false. Эта функция была введена в Qt 4.3. See also setFirstColumnSpanned(). bool QTreeView::isIndexHidden ( const QModelIndex & index ) const [virtual protected]Переопределено из QAbstractItemView::isIndexHidden(). bool QTreeView::isRowHidden ( int row, const QModelIndex & parent ) constReturns true if the item in the given row of the parent is hidden; otherwise returns false. See also setRowHidden() and isColumnHidden(). void QTreeView::keyPressEvent ( QKeyEvent * event ) [virtual protected]Переопределено от QWidget::keyPressEvent(). void QTreeView::keyboardSearch ( const QString & search ) [virtual]Reimplemented from QAbstractItemView::keyboardSearch(). void QTreeView::mouseDoubleClickEvent ( QMouseEvent * event ) [virtual protected]Переопределено из QWidget::mouseDoubleClickEvent(). void QTreeView::mouseMoveEvent ( QMouseEvent * event ) [virtual protected]Переопределено из QWidget::mouseMoveEvent(). void QTreeView::mousePressEvent ( QMouseEvent * event ) [virtual protected]Переопределено из QWidget::mousePressEvent(). void QTreeView::mouseReleaseEvent ( QMouseEvent * event ) [virtual protected]Переопределено из QWidget::mouseReleaseEvent(). QModelIndex QTreeView::moveCursor ( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) [virtual protected]Переопределено из QAbstractItemView::moveCursor(). Move the cursor in the way described by cursorAction, using the information provided by the button modifiers. void QTreeView::paintEvent ( QPaintEvent * event ) [virtual protected]Переопределено от QWidget::paintEvent(). void QTreeView::reset () [virtual]Reimplemented from QAbstractItemView::reset(). 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. Эта функция была введена в Qt 4.3. See also indexRowSizeHint(). void QTreeView::rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end ) [virtual protected]Переопределено из 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. void QTreeView::rowsInserted ( const QModelIndex & parent, int start, int end ) [virtual protected]Переопределено из 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. 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. Эта функция была введена в Qt 4.1. void QTreeView::scrollContentsBy ( int dx, int dy ) [virtual protected]Переопределено из QAbstractScrollArea::scrollContentsBy(). Scrolls the contents of the tree view by (dx, dy). void QTreeView::scrollTo ( const QModelIndex & index, ScrollHint hint = EnsureVisible ) [virtual]Переопределено из 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. void QTreeView::selectAll () [virtual]Reimplemented from QAbstractItemView::selectAll(). QModelIndexList QTreeView::selectedIndexes () const [virtual protected]Переопределено из QAbstractItemView::selectedIndexes(). void QTreeView::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) [virtual protected]Переопределено из QAbstractItemView::selectionChanged(). 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. Эта функция была введена в 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. Эта функция была введена в 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::setModel ( QAbstractItemModel * model ) [virtual]Reimplemented from QAbstractItemView::setModel(). void QTreeView::setRootIndex ( const QModelIndex & index ) [virtual]Reimplemented from QAbstractItemView::setRootIndex(). 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]Переопределено из QAbstractItemView::setSelection(). Applies the selection command to the items in or touched by the rectangle, rect. See also selectionCommand(). void QTreeView::setSelectionModel ( QItemSelectionModel * selectionModel ) [virtual]Переопределено от QAbstractItemView::setSelectionModel(). 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]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(). void QTreeView::sortByColumn ( int column, Qt::SortOrder order )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. Эта функция была введена в Qt 4.2. See also sortingEnabled. void QTreeView::timerEvent ( QTimerEvent * event ) [virtual protected]Переопределено из QObject::timerEvent(). void QTreeView::updateGeometries () [virtual protected]Переопределено из QAbstractItemView::updateGeometries(). int QTreeView::verticalOffset () const [virtual protected]Переопределено из QAbstractItemView::verticalOffset(). Returns the vertical offset of the items in the tree view. See also horizontalOffset(). bool QTreeView::viewportEvent ( QEvent * event ) [virtual protected]Переопределено из QAbstractScrollArea::viewportEvent(). QRect QTreeView::visualRect ( const QModelIndex & index ) const [virtual]Переопределено из 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. QRegion QTreeView::visualRegionForSelection ( const QItemSelection & selection ) const [virtual protected]Переопределено из QAbstractItemView::visualRegionForSelection(). Returns the rectangle from the viewport of the items in the given selection. Начиная с 4.7, возвращённая область содержит только прямоугольники, пересекающиеся (или полностью находящиеся) в области просмотра. |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |