Qt Jambi Home

com.trolltech.qt.gui
Class QTreeView

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QWidget
                  extended by com.trolltech.qt.gui.QFrame
                      extended by com.trolltech.qt.gui.QAbstractScrollArea
                          extended by com.trolltech.qt.gui.QAbstractItemView
                              extended by com.trolltech.qt.gui.QTreeView
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface
Direct Known Subclasses:
QTreeWidget

public class QTreeView
extends QAbstractItemView

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:

KeyAction
UpArrowMoves 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.
DownArrowMoves 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.
LeftArrowHides the children of the current item (if present) by collapsing a branch.
MinusSame as LeftArrow.
RightArrowReveals the children of the current item (if present) by expanding a branch.
PlusSame as RightArrow.
AsteriskExpands all children of the current item (if present).
PageUpMoves the cursor up one page.
PageDownMoves the cursor down one page.
HomeMoves the cursor to an item in the same column of the first row of the first top-level item in the model.
EndMoves the cursor to an item in the same column of the last row of the last top-level item in the model.
F2In 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.

Screenshot of a Windows XP style tree viewScreenshot of a Macintosh style tree viewScreenshot of a Plastique style tree view
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, View Example

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QAbstractItemView
QAbstractItemView.CursorAction, QAbstractItemView.DragDropMode, QAbstractItemView.DropIndicatorPosition, QAbstractItemView.EditTrigger, QAbstractItemView.EditTriggers, QAbstractItemView.ScrollHint, QAbstractItemView.ScrollMode, QAbstractItemView.SelectionBehavior, QAbstractItemView.SelectionMode, QAbstractItemView.State
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QFrame
QFrame.Shadow, QFrame.Shape, QFrame.StyleMask
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QWidget
QWidget.RenderFlag, QWidget.RenderFlags
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal1<QModelIndex> collapsed
          This signal is emitted when the item specified by index is collapsed.
 QSignalEmitter.Signal1<QModelIndex> expanded
          This signal is emitted when the item specified by index is expanded.
 
Fields inherited from class com.trolltech.qt.gui.QAbstractItemView
activated, clicked, doubleClicked, entered, pressed, viewportEntered
 
Fields inherited from class com.trolltech.qt.gui.QWidget
customContextMenuRequested
 
Constructor Summary
QTreeView()
          Equivalent to QTreeView(0).
QTreeView(QWidget parent)
          Constructs a table view with a parent to represent a model's data.
 
Method Summary
 boolean allColumnsShowFocus()
          Returns whether items should show keyboard focus using all columns.
 int autoExpandDelay()
          Returns The delay time before items in a tree are opened during a drag and drop operation..
 void collapse(QModelIndex index)
          Collapses the model item specified by the index.
 void collapseAll()
          Collapses all expanded items.
 int columnAt(int x)
          Returns the column in the tree view whose header covers the x coordinate given.
protected  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.
protected  void columnMoved()
          This slot is called whenever a column has been moved.
protected  void columnResized(int column, int oldSize, int newSize)
          This function is called whenever column's size is changed in the header.
 int columnViewportPosition(int column)
          Returns the horizontal position of the column in the viewport.
 int columnWidth(int column)
          Returns the width of the column.
protected  void currentChanged(QModelIndex current, QModelIndex previous)
          

This slot is called when a new item becomes the current item.

protected  void dataChanged(QModelIndex topLeft, QModelIndex bottomRight)
          

This slot is called when items are changed in the model.

 void doItemsLayout()
          

protected  void dragMoveEvent(QDragMoveEvent event)
          

This function is called continuously with the given event during a drag and drop operation over the widget.

protected  void drawBranches(QPainter painter, QRect rect, QModelIndex index)
          Draws the branches in the tree view on the same row as the model item index, using the painter given.
protected  void drawRow(QPainter painter, QStyleOptionViewItem options, QModelIndex index)
          Draws the row in the tree view that contains the model item index, using the painter given.
protected  void drawTree(QPainter painter, QRegion region)
          Draws the part of the tree intersecting the given region using the specified painter.
 void expand(QModelIndex index)
          Expands the model item specified by the index.
 void expandAll()
          Expands all expandable items.
 void expandToDepth(int depth)
          Expands all expandable items to the given depth.
static QTreeView fromNativePointer(QNativePointer nativePointer)
          This function returns the QTreeView instance pointed to by nativePointer
 QHeaderView header()
          Returns the header for the tree view.
 void hideColumn(int column)
          Hides the column given.
protected  int horizontalOffset()
          Returns the horizontal offset of the items in the treeview.
protected  void horizontalScrollbarAction(int action)
          

 int indentation()
          Returns indentation of the items in the tree view..
 QModelIndex indexAbove(QModelIndex index)
          Returns the model index of the item above index.
 QModelIndex indexAt(QPoint p)
          

Returns the model index of the item at the viewport coordinates point.

 QModelIndex indexBelow(QModelIndex index)
          Returns the model index of the item below index.
protected  int indexRowSizeHint(QModelIndex index)
          Returns the size hint for the row indicated by index.
 boolean isAnimated()
          Returns whether animations are enabled.
 boolean isColumnHidden(int column)
          Returns true if the column is hidden; otherwise returns false.
 boolean isExpanded(QModelIndex index)
          Returns true if the model item index is expanded; otherwise returns false.
 boolean isFirstColumnSpanned(int row, QModelIndex parent)
          Returns true if the item in first column in the given row of the parent is spanning all the columns; otherwise returns false.
protected  boolean isIndexHidden(QModelIndex index)
          

Returns true if the item referred to by the given index is hidden in the view, otherwise returns false.

 boolean isRowHidden(int row, QModelIndex parent)
          Returns true if the item in the given row of the parent is hidden; otherwise returns false.
 boolean isSortingEnabled()
          Returns whether sorting is enabled.
 boolean itemsExpandable()
          Returns whether the items are expandable by the user..
 void keyboardSearch(java.lang.String search)
          

Moves to and selects the item best matching the string search.

protected  void keyPressEvent(QKeyEvent event)
          

This function is called with the given event when a key event is sent to the widget.

protected  void mouseDoubleClickEvent(QMouseEvent event)
          

This function is called with the given event when a mouse button is double clicked inside the widget.

protected  void mouseMoveEvent(QMouseEvent event)
          

This function is called with the given event when a mouse move event is sent to the widget.

protected  void mousePressEvent(QMouseEvent event)
          

This function is called with the given event when a mouse button is pressed while the cursor is inside the widget.

protected  void mouseReleaseEvent(QMouseEvent event)
          

This function is called with the given event when a mouse button is released, after a mouse press event on the widget.

protected  QModelIndex moveCursor(QAbstractItemView.CursorAction cursorAction, Qt.KeyboardModifiers modifiers)
          Move the cursor in the way described by cursorAction, using the information provided by the button modifiers.
protected  void paintEvent(QPaintEvent event)
          

This event handler can be reimplemented in a subclass to receive paint events (passed in arg__1), for the viewport widget.

protected  void reexpand()
          
 void reset()
          

Reset the internal state of the view.

 void resizeColumnToContents(int column)
          Resizes the column given to the size of its contents.
 boolean rootIsDecorated()
          Returns whether to show controls for expanding and collapsing top-level items.
protected  int rowHeight(QModelIndex index)
          Returns the height of the row indicated by the given index.
protected  void rowsAboutToBeRemoved(QModelIndex parent, int start, int end)
          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.
protected  void rowsInserted(QModelIndex parent, int start, int end)
          Informs the view that the rows from the start row to the end row inclusive have been inserted into the parent model item.
protected  void rowsRemoved(QModelIndex parent, int first, int last)
          Informs the view that the rows from the first row to the last row inclusive have been removed from the given parent model item.
protected  void scrollContentsBy(int dx, int dy)
          Scrolls the contents of the tree view by (dx, dy).
 void scrollTo(QModelIndex index, QAbstractItemView.ScrollHint hint)
          Scroll the contents of the tree view until the given model item index is visible.
 void selectAll()
          Selects all the items in the underlying model.
protected  java.util.List<QModelIndex> selectedIndexes()
          

This convenience function returns a list of all selected and non-hidden item indexes in the view.

protected  void selectionChanged(QItemSelection selected, QItemSelection deselected)
          

This slot is called when the selection is changed.

 void setAllColumnsShowFocus(boolean enable)
          Sets whether items should show keyboard focus using all columns to enable.
 void setAnimated(boolean enable)
          Sets whether animations are enabled to enable.
 void setAutoExpandDelay(int delay)
          Sets The delay time before items in a tree are opened during a drag and drop operation.
 void setColumnHidden(int column, boolean hide)
          If hide is true the column is hidden, otherwise the column is shown.
 void setColumnWidth(int column, int width)
          Sets the width of the given column to the width specified.
 void setExpanded(QModelIndex index, boolean expand)
          Sets the item referred to by index to either collapse or expanded, depending on the value of expand.
 void setFirstColumnSpanned(int row, QModelIndex parent, boolean 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.
 void setHeader(QHeaderView header)
          Sets the header for the tree view, to the given header.
 void setIndentation(int i)
          Sets indentation of the items in the tree view.
 void setItemsExpandable(boolean enable)
          Sets whether the items are expandable by the user.
 void setModel(QAbstractItemModel model)
          

Sets the model for the view to present.

 void setRootIndex(QModelIndex index)
          

Sets the root item to the item at the given index.

 void setRootIsDecorated(boolean show)
          Sets whether to show controls for expanding and collapsing top-level items to show.
 void setRowHidden(int row, QModelIndex parent, boolean hide)
          If hide is true the row with the given parent is hidden, otherwise the row is shown.
protected  void setSelection(QRect rect, QItemSelectionModel.SelectionFlags command)
          Applies the selection command to the items in or touched by the rectangle, rect.
 void setSelectionModel(QItemSelectionModel selectionModel)
          

Sets the current selection model to the given selectionModel.

 void setSortingEnabled(boolean enable)
          Sets whether sorting is enabled to enable.
 void setUniformRowHeights(boolean uniform)
          Sets whether all items in the treeview have the same height to uniform.
 void setWordWrap(boolean on)
          Sets the item text word-wrapping policy to on.
 void showColumn(int column)
          Shows the given column in the tree view.
 int sizeHintForColumn(int column)
          Returns the size hint for the column's width or -1 if there is no model.
 void sortByColumn(int column, Qt.SortOrder order)
          Sorts the model by the values in the given column in the given order.
protected  void timerEvent(QTimerEvent event)
          

This function is called with the given event when a timer event is sent to the widget.

 boolean uniformRowHeights()
          Returns whether all items in the treeview have the same height.
protected  void updateGeometries()
          

protected  int verticalOffset()
          Returns the vertical offset of the items in the tree view.
protected  boolean viewportEvent(QEvent event)
          

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.

 QRect visualRect(QModelIndex index)
          Returns the rectangle on the viewport occupied by the item at index.
protected  QRegion visualRegionForSelection(QItemSelection selection)
          Returns the rectangle from the viewport of the items in the given selection.
 boolean wordWrap()
          Returns the item text word-wrapping policy.
 
Methods inherited from class com.trolltech.qt.gui.QAbstractItemView
alternatingRowColors, clearSelection, closeEditor, closePersistentEditor, commitData, currentIndex, dirtyRegionOffset, doAutoScroll, dragDropMode, dragDropOverwriteMode, dragEnabled, dragEnterEvent, dragLeaveEvent, dropEvent, dropIndicatorPosition, edit, edit, editorDestroyed, editTriggers, event, executeDelayedItemsLayout, focusInEvent, focusNextPrevChild, focusOutEvent, hasAutoScroll, horizontalScrollbarValueChanged, horizontalScrollMode, iconSize, indexWidget, inputMethodEvent, inputMethodQuery, itemDelegate, itemDelegate, itemDelegateForColumn, itemDelegateForRow, model, openPersistentEditor, resizeEvent, rootIndex, scheduleDelayedItemsLayout, scrollDirtyRegion, scrollTo, scrollToBottom, scrollToTop, selectionBehavior, selectionCommand, selectionCommand, selectionMode, selectionModel, setAlternatingRowColors, setAutoScroll, setCurrentIndex, setDirtyRegion, setDragDropMode, setDragDropOverwriteMode, setDragEnabled, setDropIndicatorShown, setEditTriggers, setEditTriggers, setHorizontalScrollMode, setIconSize, setIndexWidget, setItemDelegate, setItemDelegateForColumn, setItemDelegateForRow, setSelectionBehavior, setSelectionMode, setState, setTabKeyNavigation, setTextElideMode, setVerticalScrollMode, showDropIndicator, sizeHintForIndex, sizeHintForRow, startAutoScroll, startDrag, startDrag, state, stopAutoScroll, tabKeyNavigation, textElideMode, update, updateEditorData, updateEditorGeometries, verticalScrollbarAction, verticalScrollbarValueChanged, verticalScrollMode, viewOptions
 
Methods inherited from class com.trolltech.qt.gui.QAbstractScrollArea
addScrollBarWidget, addScrollBarWidget, contextMenuEvent, cornerWidget, horizontalScrollBar, horizontalScrollBarPolicy, maximumViewportSize, minimumSizeHint, paintEngine, scrollBarWidgets, scrollBarWidgets, setCornerWidget, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setupViewport, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportMargins, sizeHint, verticalScrollBar, verticalScrollBarPolicy, viewport, wheelEvent
 
Methods inherited from class com.trolltech.qt.gui.QFrame
changeEvent, drawFrame, frameRect, frameShadow, frameShape, frameStyle, frameWidth, lineWidth, midLineWidth, setFrameRect, setFrameShadow, setFrameShape, setFrameStyle, setLineWidth, setMidLineWidth
 
Methods inherited from class com.trolltech.qt.gui.QWidget
acceptDrops, accessibleDescription, accessibleName, actionEvent, actions, activateWindow, addAction, addActions, adjustSize, autoFillBackground, backgroundRole, baseSize, childAt, childAt, childrenRect, childrenRegion, clearFocus, clearMask, close, closeEvent, contentsRect, contextMenuPolicy, createWinId, cursor, depth, destroy, destroy, destroy, devType, ensurePolished, enterEvent, focusNextChild, focusPolicy, focusPreviousChild, focusProxy, focusWidget, font, fontInfo, fontMetrics, foregroundRole, frameGeometry, frameSize, geometry, getContentsMargins, grabKeyboard, grabMouse, grabMouse, grabShortcut, grabShortcut, hasFocus, hasMouseTracking, height, heightForWidth, heightMM, hide, hideEvent, inputContext, insertAction, insertActions, isActiveWindow, isAncestorOf, isEnabled, isEnabledTo, isFullScreen, isHidden, isLeftToRight, isMaximized, isMinimized, isModal, isRightToLeft, isVisible, isVisibleTo, isWindow, isWindowModified, keyboardGrabber, keyReleaseEvent, layout, layoutDirection, leaveEvent, locale, logicalDpiX, logicalDpiY, lower, mapFrom, mapFromGlobal, mapFromParent, mapTo, mapToGlobal, mapToParent, mask, maximumHeight, maximumSize, maximumWidth, metric, minimumHeight, minimumSize, minimumWidth, mouseGrabber, move, move, moveEvent, nextInFocusChain, normalGeometry, numColors, overrideWindowFlags, overrideWindowFlags, overrideWindowState, overrideWindowState, paintingActive, palette, parentWidget, physicalDpiX, physicalDpiY, pos, raise, rect, releaseKeyboard, releaseMouse, releaseShortcut, removeAction, render, render, render, render, render, repaint, repaint, repaint, repaint, resetInputContext, resize, resize, restoreGeometry, saveGeometry, scroll, scroll, setAcceptDrops, setAccessibleDescription, setAccessibleName, setAttribute, setAttribute, setAutoFillBackground, setBackgroundRole, setBaseSize, setBaseSize, setContentsMargins, setContentsMargins, setContextMenuPolicy, setCursor, setDisabled, setEnabled, setFixedHeight, setFixedSize, setFixedSize, setFixedWidth, setFocus, setFocus, setFocusPolicy, setFocusProxy, setFont, setForegroundRole, setGeometry, setGeometry, setHidden, setInputContext, setLayout, setLayoutDirection, setLocale, setMask, setMask, setMaximumHeight, setMaximumSize, setMaximumSize, setMaximumWidth, setMinimumHeight, setMinimumSize, setMinimumSize, setMinimumWidth, setMouseTracking, setPalette, setParent, setParent, setParent, setShortcutAutoRepeat, setShortcutAutoRepeat, setShortcutEnabled, setShortcutEnabled, setSizeIncrement, setSizeIncrement, setSizePolicy, setSizePolicy, setStatusTip, setStyle, setStyleSheet, setTabOrder, setToolTip, setUpdatesEnabled, setVisible, setWhatsThis, setWindowFlags, setWindowFlags, setWindowIcon, setWindowIconText, setWindowModality, setWindowModified, setWindowOpacity, setWindowRole, setWindowState, setWindowState, setWindowTitle, show, showEvent, showFullScreen, showMaximized, showMinimized, showNormal, size, sizeIncrement, sizePolicy, stackUnder, statusTip, style, styleSheet, tabletEvent, testAttribute, toolTip, underMouse, unsetCursor, unsetLayoutDirection, unsetLocale, update, update, update, update, updateGeometry, updateMicroFocus, updatesEnabled, visibleRegion, whatsThis, width, widthMM, window, windowFlags, windowIcon, windowIconText, windowModality, windowOpacity, windowRole, windowState, windowTitle, windowType, winId, x, y
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

collapsed

public final QSignalEmitter.Signal1<QModelIndex> collapsed

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

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.core.QModelIndex index)
void mySlot()


expanded

public final QSignalEmitter.Signal1<QModelIndex> expanded

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

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.core.QModelIndex index)
void mySlot()
See Also:
setExpanded

Constructor Detail

QTreeView

public QTreeView()

Equivalent to QTreeView(0).


QTreeView

public QTreeView(QWidget parent)

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

See Also:
QAbstractItemModel
Method Detail

allColumnsShowFocus

public final boolean allColumnsShowFocus()

Returns 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.

See Also:
setAllColumnsShowFocus

autoExpandDelay

public final int autoExpandDelay()

Returns 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.

See Also:
setAutoExpandDelay

collapse

public final void collapse(QModelIndex index)

Collapses the model item specified by the index.

See Also:
collapsed

collapseAll

public final void collapseAll()

Collapses all expanded items.

See Also:
expandAll, expand, collapse, setExpanded

columnAt

public final int columnAt(int x)

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


columnCountChanged

protected final 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.


columnMoved

protected final void columnMoved()

This slot is called whenever a column has been moved.


columnResized

protected final void columnResized(int column,
                                   int oldSize,
                                   int newSize)

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

columnViewportPosition

public final int columnViewportPosition(int column)

Returns the horizontal position of the column in the viewport.


columnWidth

public final int columnWidth(int column)

Returns the width of the column.

See Also:
resizeColumnToContents, setColumnWidth

drawTree

protected final void drawTree(QPainter painter,
                              QRegion region)

Draws the part of the tree intersecting the given region using the specified painter.

See Also:
paintEvent

expand

public final void expand(QModelIndex index)

Expands the model item specified by the index.

See Also:
expanded

expandAll

public final void expandAll()

Expands all expandable items.

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

See Also:
collapseAll, expand, collapse, setExpanded

expandToDepth

public final void expandToDepth(int depth)

Expands all expandable items to the given depth.

See Also:
expandAll, collapseAll, expand, collapse, setExpanded

header

public final QHeaderView header()

Returns the header for the tree view.

See Also:
setHeader, QAbstractItemModel::headerData

hideColumn

public final void hideColumn(int column)

Hides the column given.

See Also:
showColumn, setColumnHidden

indentation

public final int indentation()

Returns 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.

See Also:
setIndentation

indexAbove

public final QModelIndex indexAbove(QModelIndex index)

Returns the model index of the item above index.


indexBelow

public final QModelIndex indexBelow(QModelIndex index)

Returns the model index of the item below index.


indexRowSizeHint

protected final int indexRowSizeHint(QModelIndex index)

Returns the size hint for the row indicated by index.

See Also:
sizeHintForColumn, uniformRowHeights

isAnimated

public final boolean isAnimated()

Returns 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.


isColumnHidden

public final boolean isColumnHidden(int column)

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

See Also:
hideColumn, isRowHidden

isExpanded

public final boolean isExpanded(QModelIndex index)

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

See Also:
expand, expanded, setExpanded

isFirstColumnSpanned

public final boolean isFirstColumnSpanned(int row,
                                          QModelIndex parent)

Returns true if the item in first column in the given row of the parent is spanning all the columns; otherwise returns false.

See Also:
setFirstColumnSpanned

isRowHidden

public final boolean isRowHidden(int row,
                                 QModelIndex parent)

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

See Also:
setRowHidden, isColumnHidden

isSortingEnabled

public final boolean isSortingEnabled()

Returns 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.

See Also:
sortByColumn

itemsExpandable

public final boolean itemsExpandable()

Returns whether the items are expandable by the user..

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

See Also:
setItemsExpandable

reexpand

protected final void reexpand()


resizeColumnToContents

public final void resizeColumnToContents(int column)

Resizes the column given to the size of its contents.

See Also:
columnWidth, setColumnWidth

rootIsDecorated

public final boolean rootIsDecorated()

Returns 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.

See Also:
setRootIsDecorated

rowHeight

protected final int rowHeight(QModelIndex index)

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

See Also:
indexRowSizeHint

rowsRemoved

protected final void rowsRemoved(QModelIndex parent,
                                 int first,
                                 int last)

Informs the view that the rows from the first row to the last row inclusive have been removed from the given parent model item.


setAllColumnsShowFocus

public final void setAllColumnsShowFocus(boolean enable)

Sets whether items should show keyboard focus using all columns to enable.

If this property is true all columns will show focus, otherwise only one column will show focus.

The default is false.

See Also:
allColumnsShowFocus

setAnimated

public final void setAnimated(boolean enable)

Sets whether animations are enabled to enable.

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.

See Also:
isAnimated

setAutoExpandDelay

public final void setAutoExpandDelay(int delay)

Sets The delay time before items in a tree are opened during a drag and drop operation. to delay.

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.

See Also:
autoExpandDelay

setColumnHidden

public final void setColumnHidden(int column,
                                  boolean hide)

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

See Also:
isColumnHidden, hideColumn, setRowHidden

setColumnWidth

public final void setColumnWidth(int column,
                                 int width)

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

See Also:
columnWidth, resizeColumnToContents

setExpanded

public final void setExpanded(QModelIndex index,
                              boolean expand)

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

See Also:
expanded, expand, isExpanded

setFirstColumnSpanned

public final void setFirstColumnSpanned(int row,
                                        QModelIndex parent,
                                        boolean 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.

See Also:
isFirstColumnSpanned

setHeader

public final void 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

setIndentation

public final void setIndentation(int i)

Sets indentation of the items in the tree view. to i.

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.

See Also:
indentation

setItemsExpandable

public final void setItemsExpandable(boolean enable)

Sets whether the items are expandable by the user. to enable.

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

See Also:
itemsExpandable

setRootIsDecorated

public final void setRootIsDecorated(boolean show)

Sets whether to show controls for expanding and collapsing top-level items to show.

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.

See Also:
rootIsDecorated

setRowHidden

public final void setRowHidden(int row,
                               QModelIndex parent,
                               boolean hide)

If hide is true the row with the given parent is hidden, otherwise the row is shown.

See Also:
isRowHidden, setColumnHidden

setSortingEnabled

public final void setSortingEnabled(boolean enable)

Sets whether sorting is enabled to enable.

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.

See Also:
isSortingEnabled, sortByColumn

setUniformRowHeights

public final void setUniformRowHeights(boolean uniform)

Sets whether all items in the treeview have the same height to uniform.

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.

See Also:
uniformRowHeights

setWordWrap

public final void setWordWrap(boolean on)

Sets the item text word-wrapping policy to on.

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.

See Also:
wordWrap

showColumn

public final void showColumn(int column)

Shows the given column in the tree view.

See Also:
hideColumn, setColumnHidden

sortByColumn

public final void sortByColumn(int column,
                               Qt.SortOrder order)

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

See Also:
sortingEnabled

uniformRowHeights

public final boolean uniformRowHeights()

Returns 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.

See Also:
setUniformRowHeights

wordWrap

public final boolean wordWrap()

Returns 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.

See Also:
setWordWrap

currentChanged

protected void currentChanged(QModelIndex current,
                              QModelIndex previous)

This slot is called when a new item becomes the current item. The previous current item is specified by the previous index, and the new item by the current index.

If you want to know about changes to items see the dataChanged signal.

Overrides:
currentChanged in class QAbstractItemView

dataChanged

protected void dataChanged(QModelIndex topLeft,
                           QModelIndex bottomRight)

This slot is called when items are changed in the model. The changed items are those from topLeft to bottomRight inclusive. If just one item is changed topLeft == bottomRight.

Overrides:
dataChanged in class QAbstractItemView

doItemsLayout

public void doItemsLayout()

Overrides:
doItemsLayout in class QAbstractItemView

dragMoveEvent

protected void dragMoveEvent(QDragMoveEvent event)

This function is called continuously with the given event during a drag and drop operation over the widget. It can cause the view to scroll if, for example, the user drags a selection to view's right or bottom edge. In this case, the event will be accepted; otherwise it will be ignored.

Overrides:
dragMoveEvent in class QAbstractItemView
See Also:
dropEvent, startDrag

drawBranches

protected void drawBranches(QPainter painter,
                            QRect rect,
                            QModelIndex index)

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.


drawRow

protected void drawRow(QPainter painter,
                       QStyleOptionViewItem options,
                       QModelIndex index)

Draws the row in the tree view that contains the model item index, using the painter given. The options control how the item is displayed.

See Also:
setAlternatingRowColors

horizontalOffset

protected int 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.

Specified by:
horizontalOffset in class QAbstractItemView
See Also:
verticalOffset

horizontalScrollbarAction

protected void horizontalScrollbarAction(int action)

Overrides:
horizontalScrollbarAction in class QAbstractItemView

indexAt

public QModelIndex indexAt(QPoint p)

Returns the model index of the item at the viewport coordinates point.

In the base class this is a pure virtual function.

Specified by:
indexAt in class QAbstractItemView
See Also:
visualRect

isIndexHidden

protected boolean isIndexHidden(QModelIndex index)

Returns true if the item referred to by the given index is hidden in the view, otherwise returns false.

Hiding is a view specific feature. For example in TableView a column can be marked as hidden or a row in the TreeView.

In the base class this is a pure virtual function.

Specified by:
isIndexHidden in class QAbstractItemView

keyPressEvent

protected void keyPressEvent(QKeyEvent event)

This function is called with the given event when a key event is sent to the widget. The default implementation handles basic cursor movement, e.g. Up, Down, Left, Right, Home, PageUp, and PageDown; the activated signal is emitted if the current index is valid and the activation key is pressed (e.g. Enter or Return, depending on the platform). This function is where editing is initiated by key press, e.g. if F2 is pressed.

Overrides:
keyPressEvent in class QAbstractItemView
See Also:
edit, moveCursor, keyboardSearch, tabKeyNavigation

keyboardSearch

public void keyboardSearch(java.lang.String search)

Moves to and selects the item best matching the string search. If no item is found nothing happens.

In the default implementation, the search is reset if search is empty, or the time interval since the last search has exceeded QApplication::keyboardInputInterval().

Overrides:
keyboardSearch in class QAbstractItemView

mouseDoubleClickEvent

protected void mouseDoubleClickEvent(QMouseEvent event)

This function is called with the given event when a mouse button is double clicked inside the widget. If the double-click is on a valid item it emits the doubleClicked signal and calls edit on the item.

Overrides:
mouseDoubleClickEvent in class QAbstractItemView
See Also:
QWidget::mouseDoubleClickEvent

mouseMoveEvent

protected void mouseMoveEvent(QMouseEvent event)

This function is called with the given event when a mouse move event is sent to the widget. If a selection is in progress and new items are moved over the selection is extended; if a drag is in progress it is continued.

Overrides:
mouseMoveEvent in class QAbstractItemView
See Also:
QWidget::mouseMoveEvent

mousePressEvent

protected void mousePressEvent(QMouseEvent event)

This function is called with the given event when a mouse button is pressed while the cursor is inside the widget. If a valid item is pressed on it is made into the current item. This function emits the pressed signal.

Overrides:
mousePressEvent in class QAbstractItemView
See Also:
QWidget::mousePressEvent

mouseReleaseEvent

protected void mouseReleaseEvent(QMouseEvent event)

This function is called with the given event when a mouse button is released, after a mouse press event on the widget. If a user presses the mouse inside your widget and then drags the mouse to another location before releasing the mouse button, your widget receives the release event. The function will emit the clicked signal if an item was being pressed.

Overrides:
mouseReleaseEvent in class QAbstractItemView
See Also:
QWidget::mouseReleaseEvent

moveCursor

protected QModelIndex moveCursor(QAbstractItemView.CursorAction cursorAction,
                                 Qt.KeyboardModifiers modifiers)

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

Specified by:
moveCursor in class QAbstractItemView

paintEvent

protected void paintEvent(QPaintEvent event)

This event handler can be reimplemented in a subclass to receive paint events (passed in arg__1), for the viewport widget.

Note: If you open a painter, make sure to open it on the viewport.

Overrides:
paintEvent in class QAbstractScrollArea
See Also:
QWidget::paintEvent

reset

public void reset()

Reset the internal state of the view.

Overrides:
reset in class QAbstractItemView

rowsAboutToBeRemoved

protected void rowsAboutToBeRemoved(QModelIndex parent,
                                    int start,
                                    int end)

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.

Overrides:
rowsAboutToBeRemoved in class QAbstractItemView
See Also:
rowsInserted

rowsInserted

protected void rowsInserted(QModelIndex parent,
                            int start,
                            int end)

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

Overrides:
rowsInserted in class QAbstractItemView
See Also:
rowsAboutToBeRemoved

scrollContentsBy

protected void scrollContentsBy(int dx,
                                int dy)

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

Overrides:
scrollContentsBy in class QAbstractScrollArea

scrollTo

public void scrollTo(QModelIndex index,
                     QAbstractItemView.ScrollHint hint)

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.

Specified by:
scrollTo in class QAbstractItemView

selectAll

public void selectAll()

Selects all the items in the underlying model.

Overrides:
selectAll in class QAbstractItemView
See Also:
setSelection, selectedIndexes, clearSelection

selectedIndexes

protected java.util.List<QModelIndex> selectedIndexes()

This convenience function returns a list of all selected and non-hidden item indexes in the view. The list contains no duplicates, and is not sorted.

The default implementation does nothing.

Overrides:
selectedIndexes in class QAbstractItemView
See Also:
QItemSelectionModel::selectedIndexes

selectionChanged

protected void selectionChanged(QItemSelection selected,
                                QItemSelection deselected)

This slot is called when the selection is changed. The previous selection (which may be empty), is specified by deselected, and the new selection by selected.

Overrides:
selectionChanged in class QAbstractItemView
See Also:
setSelection

setModel

public void setModel(QAbstractItemModel model)

Sets the model for the view to present.

Note: This function will also create and set a new selection model, replacing any previously set with setSelectionModel, but the old selection model will not be deleted.

Overrides:
setModel in class QAbstractItemView
See Also:
model, selectionModel, setSelectionModel

setRootIndex

public void setRootIndex(QModelIndex index)

Sets the root item to the item at the given index.

Overrides:
setRootIndex in class QAbstractItemView
See Also:
rootIndex

setSelection

protected void setSelection(QRect rect,
                            QItemSelectionModel.SelectionFlags command)

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

Specified by:
setSelection in class QAbstractItemView
See Also:
selectionCommand

setSelectionModel

public void setSelectionModel(QItemSelectionModel selectionModel)

Sets the current selection model to the given selectionModel.

Note that, if you call setModel after this function, the given selectionModel will be replaced by a one created by the view.

Overrides:
setSelectionModel in class QAbstractItemView
See Also:
selectionModel, setModel, clearSelection

sizeHintForColumn

public int sizeHintForColumn(int column)

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.

Overrides:
sizeHintForColumn in class QAbstractItemView
See Also:
QWidget::sizeHint, header

timerEvent

protected void timerEvent(QTimerEvent event)

This function is called with the given event when a timer event is sent to the widget.

Overrides:
timerEvent in class QAbstractItemView
See Also:
QObject::timerEvent

updateGeometries

protected void updateGeometries()

Overrides:
updateGeometries in class QAbstractItemView

verticalOffset

protected int verticalOffset()

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

Specified by:
verticalOffset in class QAbstractItemView
See Also:
horizontalOffset

viewportEvent

protected boolean viewportEvent(QEvent event)

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. It passes all other events on to its base class viewportEvent handler.

Overrides:
viewportEvent in class QAbstractItemView

visualRect

public QRect visualRect(QModelIndex index)

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.

Specified by:
visualRect in class QAbstractItemView
See Also:
indexAt, visualRegionForSelection

visualRegionForSelection

protected QRegion visualRegionForSelection(QItemSelection selection)

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

Specified by:
visualRegionForSelection in class QAbstractItemView
See Also:
visualRect, selectedIndexes

fromNativePointer

public static QTreeView fromNativePointer(QNativePointer nativePointer)
This function returns the QTreeView instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home