Qt Jambi Home

com.trolltech.qt.gui
Class QTreeWidget

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
                                  extended by com.trolltech.qt.gui.QTreeWidget
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QTreeWidget
extends QTreeView

The QTreeWidget class provides a tree view that uses a predefined tree model.

The QTreeWidget class is a convenience class that provides a standard tree widget with a classic item-based interface similar to that used by the QListView class in Qt 3. This class is based on Qt's Model/View architecture and uses a default model to hold items, each of which is a QTreeWidgetItem.

Developers who do not need the flexibility of the Model/View framework can use this class to create simple hierarchical lists very easily. A more flexible approach involves combining a QTreeView with a standard item model. This allows the storage of data to be separated from its representation.

In its simplest form, a tree widget can be constructed in the following way:

    QTreeWidget *treeWidget = new QTreeWidget();
    treeWidget->setColumnCount(1);
    QList<QTreeWidgetItem *> items;
    for (int i = 0; i < 10; ++i)
        items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
    treeWidget->insertTopLevelItems(0, items);

Before items can be added to the tree widget, the number of columns must be set with setColumnCount. This allows each item to have one or more labels or other decorations. The number of columns in use can be found with the columnCount function.

The tree can have a header that contains a section for each column in the widget. It is easiest to set up the labels for each section by supplying a list of strings with setHeaderLabels, but a custom header can be constructed with a QTreeWidgetItem and inserted into the tree with the setHeaderItem function.

The items in the tree can be sorted by column according to a predefined sort order. If sorting is enabled, the user can sort the items by clicking on a column header. Sorting can be enabled or disabled by calling setSortingEnabled. The isSortingEnabled function indicates whether sorting is enabled.

Screenshot of a Windows XP style tree widgetScreenshot of a Macintosh style tree widgetScreenshot of a Plastique style tree widget
A Windows XP style tree widget.A Macintosh style tree widget.A Plastique style tree widget.

See Also:
QTreeWidgetItem, QTreeView, Model/View Programming, Editor 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.AbstractSignal, 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.Signal2<QTreeWidgetItem,QTreeWidgetItem> currentItemChanged
          This signal is emitted when the current item changes.
 QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemActivated
          This signal is emitted when the user activates an item by single- or double-clicking (depending on the platform, i.e. on the QStyle::SH_ItemView_ActivateItemOnSingleClick style hint) or pressing a special key (e.g., Enter).
 QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemChanged
          This signal is emitted when the contents of the column in the specified item changes.
 QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemClicked
          This signal is emitted when the user clicks inside the widget.
 QSignalEmitter.Signal1<QTreeWidgetItem> itemCollapsed
          This signal is emitted when the specified item is collapsed so that none of its children are displayed.
 QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemDoubleClicked
          This signal is emitted when the user double clicks inside the widget.
 QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemEntered
          This signal is emitted when the mouse cursor enters an item over the specified column.
 QSignalEmitter.Signal1<QTreeWidgetItem> itemExpanded
          This signal is emitted when the specified item is expanded so that all of its children are displayed.
 QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemPressed
          This signal is emitted when the user presses a mouse button inside the widget.
 QSignalEmitter.Signal0 itemSelectionChanged
          This signal is emitted when the selection changes in the tree widget.
 
Fields inherited from class com.trolltech.qt.gui.QTreeView
collapsed, 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
QTreeWidget()
          Equivalent to QTreeWidget(0).
QTreeWidget(QWidget parent)
          Constructs a tree widget with the given parent.
 
Method Summary
 void addTopLevelItem(QTreeWidgetItem item)
          Appends the item as a top-level item in the widget.
 void addTopLevelItems(java.util.List<QTreeWidgetItem> items)
          Appends the list of items as a top-level items in the widget.
 void clear()
          Clears the tree widget by removing all of its items and selections.
 void closePersistentEditor(QTreeWidgetItem item)
          Equivalent to closePersistentEditor(item, 0).
 void closePersistentEditor(QTreeWidgetItem item, int column)
          Closes the persistent editor for the item in the given column.
 void collapseItem(QTreeWidgetItem item)
          Closes the item.
 int columnCount()
          Returns the number of columns displayed in the tree widget.
 int currentColumn()
          Returns the current column in the tree widget.
 QTreeWidgetItem currentItem()
          Returns the current item in the tree widget.
protected  void dropEvent(QDropEvent event)
          This function is reimplemented for internal reasons.
protected  boolean dropMimeData(QTreeWidgetItem parent, int index, QMimeData data, Qt.DropAction action)
          Handles the data supplied by a drag and drop operation that ended with the given action in the index in the given parent item.
 void editItem(QTreeWidgetItem item)
          Equivalent to editItem(item, 0).
 void editItem(QTreeWidgetItem item, int column)
          Starts editing the item in the given column if it is editable.
 boolean event(QEvent e)
          This function is reimplemented for internal reasons.
 void expandItem(QTreeWidgetItem item)
          Expands the item.
 java.util.List<QTreeWidgetItem> findItems(java.lang.String text, Qt.MatchFlags flags)
          Returns a list of items that match the given text, using the given flags.
 java.util.List<QTreeWidgetItem> findItems(java.lang.String text, Qt.MatchFlags flags, int column)
          Returns a list of items that match the given text, using the given flags, in the given column.
static QTreeWidget fromNativePointer(QNativePointer nativePointer)
          This function returns the QTreeWidget instance pointed to by nativePointer
 QTreeWidgetItem headerItem()
          Returns the item used for the tree widget's header.
protected  QModelIndex indexFromItem(QTreeWidgetItem item)
          Equivalent to indexFromItem(item, 0).
protected  QModelIndex indexFromItem(QTreeWidgetItem item, int column)
          Returns the QModelIndex assocated with the given item in the given column.
 int indexOfTopLevelItem(QTreeWidgetItem item)
          Returns the index of the given top-level item, or -1 if the item cannot be found.
 void insertTopLevelItem(int index, QTreeWidgetItem item)
          Inserts the item at index in the top level in the view.
 void insertTopLevelItems(int index, java.util.List<QTreeWidgetItem> items)
          Inserts the list of items at index in the top level in the view.
 QTreeWidgetItem invisibleRootItem()
          Returns the tree widget's invisible root item.
 boolean isFirstItemColumnSpanned(QTreeWidgetItem item)
          Returns true if the given item is set to show only one section over all columns; otherwise returns false.
 QTreeWidgetItem itemAbove(QTreeWidgetItem item)
          Returns the item above the given item.
 QTreeWidgetItem itemAt(int x, int y)
          Returns a pointer to the item at the coordinates (x, y).
 QTreeWidgetItem itemAt(QPoint p)
          Returns a pointer to the item at the coordinates p.
 QTreeWidgetItem itemBelow(QTreeWidgetItem item)
          Returns the item below the givenitem.
protected  QTreeWidgetItem itemFromIndex(QModelIndex index)
          Returns a pointer to the QTreeWidgetItem assocated with the given index.
 QWidget itemWidget(QTreeWidgetItem item, int column)
          Returns the widget displayed in the cell specified by item and the given column.
protected  QMimeData mimeData(java.util.List<QTreeWidgetItem> items)
          Returns an object that contains a serialized description of the specified items.
protected  java.util.List<java.lang.String> mimeTypes()
          Returns a list of MIME types that can be used to describe a list of treewidget items.
 void openPersistentEditor(QTreeWidgetItem item)
          Equivalent to openPersistentEditor(item, 0).
 void openPersistentEditor(QTreeWidgetItem item, int column)
          Opens a persistent editor for the item in the given column.
 void removeItemWidget(QTreeWidgetItem item, int column)
          Removes the widget set in the given item in the given column.
 void scrollToItem(QTreeWidgetItem item)
          Equivalent to scrollToItem(item, EnsureVisible).
 void scrollToItem(QTreeWidgetItem item, QAbstractItemView.ScrollHint hint)
          Ensures that the item is visible, scrolling the view if necessary using the specified hint.
 java.util.List<QTreeWidgetItem> selectedItems()
          Returns a list of all selected non-hidden items.
 void setColumnCount(int columns)
          Sets the number of columns displayed in the tree widget to columns.
 void setCurrentItem(QTreeWidgetItem item)
          Sets the current item in the tree widget.
 void setCurrentItem(QTreeWidgetItem item, int column)
          Sets the current item in the tree widget and the curernt column to column.
 void setFirstItemColumnSpanned(QTreeWidgetItem item, boolean span)
          Sets the given item to only show one section for all columns if span is true; otherwise the item will show one section per column.
 void setHeaderItem(QTreeWidgetItem item)
          Sets the header item for the tree widget.
 void setHeaderLabel(java.lang.String label)
          Same as setHeaderLabels(QStringList(label)).
 void setHeaderLabels(java.util.List<java.lang.String> labels)
          Adds a column in the header for each item in the labels list, and sets the label for each column.
 void setItemWidget(QTreeWidgetItem item, int column, QWidget widget)
          Sets the given widget to be displayed in the cell specified by the given item and column.
 void setModel(QAbstractItemModel model)
          Deprecated. 
 int sortColumn()
          Returns the column used to sort the contents of the widget.
 void sortItems(int column, Qt.SortOrder order)
          Sorts the items in the widget in the specified order by the values in the given column.
protected  Qt.DropActions supportedDropActions()
          Returns the drop actions supported by this view.
 QTreeWidgetItem takeTopLevelItem(int index)
          Removes the top-level item at the given index in the tree and returns it, otherwise returns 0;
 QTreeWidgetItem topLevelItem(int index)
          Returns the top level item at the given index, or 0 if the item does not exist.
 int topLevelItemCount()
          Returns the number of top-level items.
 QRect visualItemRect(QTreeWidgetItem item)
          Returns the rectangle on the viewport occupied by the item at item.
 
Methods inherited from class com.trolltech.qt.gui.QTreeView
allColumnsShowFocus, autoExpandDelay, collapse, collapseAll, columnAt, columnCountChanged, columnMoved, columnResized, columnViewportPosition, columnWidth, currentChanged, dataChanged, doItemsLayout, dragMoveEvent, drawBranches, drawRow, drawTree, expand, expandAll, expandToDepth, header, hideColumn, horizontalOffset, horizontalScrollbarAction, indentation, indexAbove, indexAt, indexBelow, indexRowSizeHint, isAnimated, isColumnHidden, isExpanded, isFirstColumnSpanned, isIndexHidden, isRowHidden, isSortingEnabled, itemsExpandable, keyboardSearch, keyPressEvent, mouseDoubleClickEvent, mouseMoveEvent, mousePressEvent, mouseReleaseEvent, moveCursor, paintEvent, reexpand, reset, resizeColumnToContents, rootIsDecorated, rowHeight, rowsAboutToBeRemoved, rowsInserted, rowsRemoved, scrollContentsBy, scrollTo, selectAll, selectedIndexes, selectionChanged, setAllColumnsShowFocus, setAnimated, setAutoExpandDelay, setColumnHidden, setColumnWidth, setExpanded, setFirstColumnSpanned, setHeader, setIndentation, setItemsExpandable, setRootIndex, setRootIsDecorated, setRowHidden, setSelection, setSelectionModel, setSortingEnabled, setUniformRowHeights, setWordWrap, showColumn, sizeHintForColumn, sortByColumn, timerEvent, uniformRowHeights, updateGeometries, verticalOffset, viewportEvent, visualRect, visualRegionForSelection, wordWrap
 
Methods inherited from class com.trolltech.qt.gui.QAbstractItemView
alternatingRowColors, clearSelection, closeEditor, closePersistentEditor, commitData, currentIndex, dirtyRegionOffset, doAutoScroll, dragDropMode, dragDropOverwriteMode, dragEnabled, dragEnterEvent, dragLeaveEvent, dropIndicatorPosition, edit, edit, editorDestroyed, editTriggers, 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

currentItemChanged

public final QSignalEmitter.Signal2<QTreeWidgetItem,QTreeWidgetItem> currentItemChanged

This signal is emitted when the current item changes. The current item is specified by current, and this replaces the previous current item.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem current, com.trolltech.qt.gui.QTreeWidgetItem previous)
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem current)
void mySlot()
See Also:
setCurrentItem


itemActivated

public final QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemActivated

This signal is emitted when the user activates an item by single- or double-clicking (depending on the platform, i.e. on the QStyle::SH_ItemView_ActivateItemOnSingleClick style hint) or pressing a special key (e.g., Enter).

The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item, int column)
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()


itemChanged

public final QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemChanged

This signal is emitted when the contents of the column in the specified item changes.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item, int column)
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()


itemClicked

public final QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemClicked

This signal is emitted when the user clicks inside the widget.

The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item, int column)
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()


itemCollapsed

public final QSignalEmitter.Signal1<QTreeWidgetItem> itemCollapsed

This signal is emitted when the specified item is collapsed so that none of its children are displayed.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()
See Also:
isItemExpanded, itemExpanded, collapseItem


itemDoubleClicked

public final QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemDoubleClicked

This signal is emitted when the user double clicks inside the widget.

The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item, int column)
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()


itemEntered

public final QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemEntered

This signal is emitted when the mouse cursor enters an item over the specified column. QTreeWidget mouse tracking needs to be enabled for this feature to work.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item, int column)
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()


itemExpanded

public final QSignalEmitter.Signal1<QTreeWidgetItem> itemExpanded

This signal is emitted when the specified item is expanded so that all of its children are displayed.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()
See Also:
isItemExpanded, itemCollapsed, expandItem


itemPressed

public final QSignalEmitter.Signal2<QTreeWidgetItem,java.lang.Integer> itemPressed

This signal is emitted when the user presses a mouse button inside the widget.

The specified item is the item that was clicked, or 0 if no item was clicked. The column is the item's column that was clicked, or -1 if no item was clicked.

Compatible Slot Signatures:
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item, int column)
void mySlot(com.trolltech.qt.gui.QTreeWidgetItem item)
void mySlot()


itemSelectionChanged

public final QSignalEmitter.Signal0 itemSelectionChanged

This signal is emitted when the selection changes in the tree widget. The current selection can be found with selectedItems.

Compatible Slot Signature:
void mySlot()

Constructor Detail

QTreeWidget

public QTreeWidget()

Equivalent to QTreeWidget(0).


QTreeWidget

public QTreeWidget(QWidget parent)

Constructs a tree widget with the given parent.

Method Detail

addTopLevelItem

public final void addTopLevelItem(QTreeWidgetItem item)

Appends the item as a top-level item in the widget.

See Also:
insertTopLevelItem

addTopLevelItems

public final void addTopLevelItems(java.util.List<QTreeWidgetItem> items)

Appends the list of items as a top-level items in the widget.

See Also:
insertTopLevelItems

clear

public final void clear()

Clears the tree widget by removing all of its items and selections.

Note: Since each item is removed from the tree widget before being deleted, the return value of QTreeWidgetItem::treeWidget() will be invalid when called from an item's destructor.

See Also:
takeTopLevelItem, topLevelItemCount, columnCount

closePersistentEditor

public final void closePersistentEditor(QTreeWidgetItem item)

Equivalent to closePersistentEditor(item, 0).


closePersistentEditor

public final void closePersistentEditor(QTreeWidgetItem item,
                                        int column)

Closes the persistent editor for the item in the given column.

This function has no effect if no persistent editor is open for this combination of item and column.

See Also:
openPersistentEditor

collapseItem

public final void collapseItem(QTreeWidgetItem item)

Closes the item. This causes the tree containing the item's children to be collapsed.

See Also:
expandItem, currentItem, itemAt, topLevelItem

columnCount

public final int columnCount()

Returns the number of columns displayed in the tree widget.

See Also:
setColumnCount

currentColumn

public final int currentColumn()

Returns the current column in the tree widget.

See Also:
setCurrentItem, columnCount

currentItem

public final QTreeWidgetItem currentItem()

Returns the current item in the tree widget.

See Also:
setCurrentItem, currentItemChanged

editItem

public final void editItem(QTreeWidgetItem item)

Equivalent to editItem(item, 0).


editItem

public final void editItem(QTreeWidgetItem item,
                           int column)

Starts editing the item in the given column if it is editable.


expandItem

public final void expandItem(QTreeWidgetItem item)

Expands the item. This causes the tree containing the item's children to be expanded.

See Also:
collapseItem, currentItem, itemAt, topLevelItem, itemExpanded

findItems

public final java.util.List<QTreeWidgetItem> findItems(java.lang.String text,
                                                       Qt.MatchFlags flags)
Returns a list of items that match the given text, using the given flags.


findItems

public final java.util.List<QTreeWidgetItem> findItems(java.lang.String text,
                                                       Qt.MatchFlags flags,
                                                       int column)

Returns a list of items that match the given text, using the given flags, in the given column.


headerItem

public final QTreeWidgetItem headerItem()

Returns the item used for the tree widget's header.

See Also:
setHeaderItem

indexFromItem

protected final QModelIndex indexFromItem(QTreeWidgetItem item)

Equivalent to indexFromItem(item, 0).


indexFromItem

protected final QModelIndex indexFromItem(QTreeWidgetItem item,
                                          int column)

Returns the QModelIndex assocated with the given item in the given column.

See Also:
itemFromIndex, topLevelItem

indexOfTopLevelItem

public final int indexOfTopLevelItem(QTreeWidgetItem item)

Returns the index of the given top-level item, or -1 if the item cannot be found.

See Also:
sortItems, topLevelItemCount

insertTopLevelItem

public final void insertTopLevelItem(int index,
                                     QTreeWidgetItem item)

Inserts the item at index in the top level in the view.

If the item has already been inserted somewhere else it wont be inserted.

See Also:
addTopLevelItem, columnCount

insertTopLevelItems

public final void insertTopLevelItems(int index,
                                      java.util.List<QTreeWidgetItem> items)

Inserts the list of items at index in the top level in the view.

Items that have already been inserted somewhere else wont be inserted.

See Also:
addTopLevelItems

invisibleRootItem

public final QTreeWidgetItem invisibleRootItem()

Returns the tree widget's invisible root item.

The invisible root item provides access to the tree widget's top-level items through the QTreeWidgetItem API, making it possible to write functions that can treat top-level items and their children in a uniform way; for example, recursive functions.


isFirstItemColumnSpanned

public final boolean isFirstItemColumnSpanned(QTreeWidgetItem item)

Returns true if the given item is set to show only one section over all columns; otherwise returns false.

See Also:
setFirstItemColumnSpanned

itemAbove

public final QTreeWidgetItem itemAbove(QTreeWidgetItem item)

Returns the item above the given item.


itemAt

public final QTreeWidgetItem itemAt(int x,
                                    int y)

Returns a pointer to the item at the coordinates (x, y).


itemAt

public final QTreeWidgetItem itemAt(QPoint p)

Returns a pointer to the item at the coordinates p.

See Also:
visualItemRect

itemBelow

public final QTreeWidgetItem itemBelow(QTreeWidgetItem item)

Returns the item below the givenitem.


itemFromIndex

protected final QTreeWidgetItem itemFromIndex(QModelIndex index)

Returns a pointer to the QTreeWidgetItem assocated with the given index.

See Also:
indexFromItem

itemWidget

public final QWidget itemWidget(QTreeWidgetItem item,
                                int column)

Returns the widget displayed in the cell specified by item and the given column.

See Also:
setItemWidget

openPersistentEditor

public final void openPersistentEditor(QTreeWidgetItem item)

Equivalent to openPersistentEditor(item, 0).


openPersistentEditor

public final void openPersistentEditor(QTreeWidgetItem item,
                                       int column)

Opens a persistent editor for the item in the given column.

See Also:
closePersistentEditor

removeItemWidget

public final void removeItemWidget(QTreeWidgetItem item,
                                   int column)

Removes the widget set in the given item in the given column.


scrollToItem

public final void scrollToItem(QTreeWidgetItem item)

Equivalent to scrollToItem(item, EnsureVisible).


scrollToItem

public final void scrollToItem(QTreeWidgetItem item,
                               QAbstractItemView.ScrollHint hint)

Ensures that the item is visible, scrolling the view if necessary using the specified hint.

See Also:
currentItem, itemAt, topLevelItem

selectedItems

public final java.util.List<QTreeWidgetItem> selectedItems()

Returns a list of all selected non-hidden items.

See Also:
itemSelectionChanged

setColumnCount

public final void setColumnCount(int columns)

Sets the number of columns displayed in the tree widget to columns.

See Also:
columnCount

setCurrentItem

public final void setCurrentItem(QTreeWidgetItem item)

Sets the current item in the tree widget.

Depending on the current selection mode, the item may also be selected.

See Also:
currentItem, currentItemChanged

setCurrentItem

public final void setCurrentItem(QTreeWidgetItem item,
                                 int column)

Sets the current item in the tree widget and the curernt column to column.

See Also:
currentItem

setFirstItemColumnSpanned

public final void setFirstItemColumnSpanned(QTreeWidgetItem item,
                                            boolean span)

Sets the given item to only show one section for all columns if span is true; otherwise the item will show one section per column.

See Also:
isFirstItemColumnSpanned

setHeaderItem

public final void setHeaderItem(QTreeWidgetItem item)

Sets the header item for the tree widget. The label for each column in the header is supplied by the corresponding label in the item.

The tree widget takes ownership of the item.

See Also:
headerItem, setHeaderLabels

setHeaderLabel

public final void setHeaderLabel(java.lang.String label)

Same as setHeaderLabels(QStringList(label)).


setHeaderLabels

public final void setHeaderLabels(java.util.List<java.lang.String> labels)

Adds a column in the header for each item in the labels list, and sets the label for each column.

Note that setHeaderLabels won't remove existing columns.

See Also:
setHeaderItem, setHeaderLabel

setItemWidget

public final void setItemWidget(QTreeWidgetItem item,
                                int column,
                                QWidget widget)

Sets the given widget to be displayed in the cell specified by the given item and column.

Note that the given widget's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the tree widget item.

This function should only be used to display static content in the place of a tree widget item. If you want to display custom dynamic content or implement a custom editor widget, use QTreeView and subclass QItemDelegate instead.

See Also:
itemWidget, Delegate Classes

setModel

@Deprecated
public final void setModel(QAbstractItemModel model)
Deprecated. 

This function is reimplemented for internal reasons.

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

sortColumn

public final int sortColumn()

Returns the column used to sort the contents of the widget.

See Also:
sortItems

sortItems

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

Sorts the items in the widget in the specified order by the values in the given column.

See Also:
sortColumn

takeTopLevelItem

public final QTreeWidgetItem takeTopLevelItem(int index)

Removes the top-level item at the given index in the tree and returns it, otherwise returns 0;

See Also:
insertTopLevelItem, topLevelItem, topLevelItemCount

topLevelItem

public final QTreeWidgetItem topLevelItem(int index)

Returns the top level item at the given index, or 0 if the item does not exist.

See Also:
topLevelItemCount, insertTopLevelItem

topLevelItemCount

public final int topLevelItemCount()

Returns the number of top-level items.

See Also:
columnCount, currentItem

visualItemRect

public final QRect visualItemRect(QTreeWidgetItem item)

Returns the rectangle on the viewport occupied by the item at item.

See Also:
itemAt

dropEvent

protected void dropEvent(QDropEvent event)

This function is reimplemented for internal reasons.

Overrides:
dropEvent in class QAbstractItemView
See Also:
startDrag

dropMimeData

protected boolean dropMimeData(QTreeWidgetItem parent,
                               int index,
                               QMimeData data,
                               Qt.DropAction action)

Handles the data supplied by a drag and drop operation that ended with the given action in the index in the given parent item.

The default implementation returns true if the drop was successfully handled by decoding the mime data and inserting it into the model; otherwise it returns false.

See Also:
supportedDropActions

event

public boolean event(QEvent e)

This function is reimplemented for internal reasons.

Overrides:
event in class QAbstractItemView
See Also:
QEvent::type

mimeData

protected QMimeData mimeData(java.util.List<QTreeWidgetItem> items)

Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes function.

If the list of items is empty, 0 is returned rather than a serialized empty list.


mimeTypes

protected java.util.List<java.lang.String> mimeTypes()

Returns a list of MIME types that can be used to describe a list of treewidget items.

See Also:
mimeData

supportedDropActions

protected Qt.DropActions supportedDropActions()

Returns the drop actions supported by this view.

See Also:
Qt::DropActions

fromNativePointer

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

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

Qt Jambi Home