|  | Home · All Classes · Modules

# QTreeWidgetItem Class Reference
[QtGui module]

The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class. More...

### Types

- enum ChildIndicatorPolicy { ShowIndicator, DontShowIndicator, DontShowIndicatorWhenChildless }
- enum ItemType { Type, UserType }

### Methods

- __init__ (self, int type = QTreeWidgetItem.Type)
- __init__ (self, QStringList, int type = QTreeWidgetItem.Type)
- __init__ (self, QTreeWidget, int type = QTreeWidgetItem.Type)
- __init__ (self, QTreeWidget, QStringList, int type = QTreeWidgetItem.Type)
- __init__ (self, QTreeWidget, QTreeWidgetItem, int type = QTreeWidgetItem.Type)
- __init__ (self, QTreeWidgetItem, int type = QTreeWidgetItem.Type)
- __init__ (self, QTreeWidgetItem, QStringList, int type = QTreeWidgetItem.Type)
- __init__ (self, QTreeWidgetItem, QTreeWidgetItem, int type = QTreeWidgetItem.Type)
- __init__ (self, QTreeWidgetItem)
- addChild (self, QTreeWidgetItem)
- addChildren (self, list-of-QTreeWidgetItem)
- QBrush background (self, int)
- QColor backgroundColor (self, int)
- Qt.CheckState checkState (self, int)
- QTreeWidgetItem child (self, int)
- int childCount (self)
- ChildIndicatorPolicy childIndicatorPolicy (self)
- QTreeWidgetItem clone (self)
- int columnCount (self)
- QVariant data (self, int, int)
- emitDataChanged (self)
- Qt.ItemFlags flags (self)
- QFont font (self, int)
- QBrush foreground (self, int)
- QIcon icon (self, int)
- int indexOfChild (self, QTreeWidgetItem)
- insertChild (self, int, QTreeWidgetItem)
- insertChildren (self, int, list-of-QTreeWidgetItem)
- bool isDisabled (self)
- bool isExpanded (self)
- bool isFirstColumnSpanned (self)
- bool isHidden (self)
- bool isSelected (self)
- QTreeWidgetItem parent (self)
- read (self, QDataStream)
- removeChild (self, QTreeWidgetItem)
- setBackground (self, int, QBrush)
- setBackgroundColor (self, int, QColor)
- setCheckState (self, int, Qt.CheckState)
- setChildIndicatorPolicy (self, ChildIndicatorPolicy)
- setData (self, int, int, QVariant)
- setDisabled (self, bool)
- setExpanded (self, bool)
- setFirstColumnSpanned (self, bool)
- setFlags (self, Qt.ItemFlags)
- setFont (self, int, QFont)
- setForeground (self, int, QBrush)
- setHidden (self, bool)
- setIcon (self, int, QIcon)
- setSelected (self, bool)
- setSizeHint (self, int, QSize)
- setStatusTip (self, int, QString)
- setText (self, int, QString)
- setTextAlignment (self, int, int)
- setTextColor (self, int, QColor)
- setToolTip (self, int, QString)
- setWhatsThis (self, int, QString)
- QSize sizeHint (self, int)
- sortChildren (self, int, Qt.SortOrder)
- QString statusTip (self, int)
- QTreeWidgetItem takeChild (self, int)
- list-of-QTreeWidgetItem takeChildren (self)
- QString text (self, int)
- int textAlignment (self, int)
- QColor textColor (self, int)
- QString toolTip (self, int)
- QTreeWidget treeWidget (self)
- int type (self)
- QString whatsThis (self, int)
- write (self, QDataStream)

### Special Methods

- bool __ge__ (self, QTreeWidgetItem)
- bool __lt__ (self, QTreeWidgetItem)

## Detailed Description

The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class.

Tree widget items are used to hold rows of information for tree widgets. Rows usually contain several columns of data, each of which can contain a text label and an icon.

The QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with the QTreeWidget class.

Items are usually constructed with a parent that is either a QTreeWidget (for top-level items) or a QTreeWidgetItem (for items on lower levels of the tree). For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:

         QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget);
         cities->setText(0, tr("Cities"));
         QTreeWidgetItem *osloItem = new QTreeWidgetItem(cities);
         osloItem->setText(0, tr("Oslo"));
         osloItem->setText(1, tr("Yes"));

Items can be added in a particular order by specifying the item they follow when they are constructed:

         QTreeWidgetItem *planets = new QTreeWidgetItem(treeWidget, cities);
         planets->setText(0, tr("Planets"));

Each column in an item can have its own background brush which is set with the setBackground() function. The current background brush can be found with background(). The text label for each column can be rendered with its own font and brush. These are specified with the setFont() and setForeground() functions, and read with font() and foreground().

The main difference between top-level items and those in lower levels of the tree is that a top-level item has no parent(). This information can be used to tell the difference between items, and is useful to know when inserting and removing items from the tree. Children of an item can be removed with takeChild() and inserted at a given index in the list of children with the insertChild() function.

By default, items are enabled, selectable, checkable, and can be the source of a drag and drop operation. Each item's flags can be changed by calling setFlags() with the appropriate value (see Qt.ItemFlags). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.

### Subclassing

When subclassing QTreeWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType.

See also QTreeWidget, QTreeWidgetItemIterator, Model/View Programming, QListWidgetItem, and QTableWidgetItem.

## Type Documentation

### QTreeWidgetItem.ChildIndicatorPolicy

Constant | Value | Description
--- | --- | ---
`QTreeWidgetItem.ShowIndicator` | `0` | The controls for expanding and collapsing will be shown for this item even if there are no children.
`QTreeWidgetItem.DontShowIndicator` | `1` | The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item.
`QTreeWidgetItem.DontShowIndicatorWhenChildless` | `2` | The controls for expanding and collapsing will be shown if the item contains children.

This enum was introduced in Qt 4.3.

### QTreeWidgetItem.ItemType

This enum describes the types that are used to describe tree widget items.

Constant | Value | Description
--- | --- | ---
`QTreeWidgetItem.Type` | `0` | The default type for tree widget items.
`QTreeWidgetItem.UserType` | `1000` | The minimum value for custom types. Values below UserType are reserved by Qt.

You can define new user types in QTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

See also type().

## Method Documentation

### QTreeWidgetItem.__init__ (self, int type = QTreeWidgetItem.Type)

Constructs a tree widget item of the specified type. The item must be inserted into a tree widget.

See also type().

### QTreeWidgetItem.__init__ (self, QStringList, int type = QTreeWidgetItem.Type)

Constructs a tree widget item of the specified type. The item must be inserted into a tree widget. The given list of strings will be set as the item text for each column in the item.

See also type().

### QTreeWidgetItem.__init__ (self, QTreeWidget, int type = QTreeWidgetItem.Type)

The QTreeWidget argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a tree widget item of the specified type and appends it to the items in the given parent.

See also type().

### QTreeWidgetItem.__init__ (self, QTreeWidget, QStringList, int type = QTreeWidgetItem.Type)

The QTreeWidget argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a tree widget item of the specified type and appends it to the items in the given parent. The given list of strings will be set as the item text for each column in the item.

See also type().

### QTreeWidgetItem.__init__ (self, QTreeWidget, QTreeWidgetItem, int type = QTreeWidgetItem.Type)

The QTreeWidget argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a tree widget item of the specified type and inserts it into the given parent after the preceding item.

See also type().

### QTreeWidgetItem.__init__ (self, QTreeWidgetItem, int type = QTreeWidgetItem.Type)

The QTreeWidgetItem argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a tree widget item and append it to the given parent.

See also type().

### QTreeWidgetItem.__init__ (self, QTreeWidgetItem, QStringList, int type = QTreeWidgetItem.Type)

The QTreeWidgetItem argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a tree widget item and append it to the given parent. The given list of strings will be set as the item text for each column in the item.

See also type().

### QTreeWidgetItem.__init__ (self, QTreeWidgetItem, QTreeWidgetItem, int type = QTreeWidgetItem.Type)

The QTreeWidgetItem argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a tree widget item of the specified type that is inserted into the parent after the preceding child item.

See also type().

### QTreeWidgetItem.__init__ (self, QTreeWidgetItem)

Constructs a copy of other. Note that type() and treeWidget() are not copied.

This function is useful when reimplementing clone().

This function was introduced in Qt 4.1.

See also data() and flags().

### QTreeWidgetItem.addChild (self, QTreeWidgetItem)

The QTreeWidgetItem argument has it's ownership transferred to Qt.

Appends the child item to the list of children.

See also insertChild() and takeChild().

### QTreeWidgetItem.addChildren (self, list-of-QTreeWidgetItem)

The list-of-QTreeWidgetItem argument has it's ownership transferred to Qt.

Appends the given list of children to the item.

This function was introduced in Qt 4.1.

See also insertChildren() and takeChildren().

### QBrush QTreeWidgetItem.background (self, int)

Returns the brush used to render the background of the specified column.

This function was introduced in Qt 4.2.

See also setBackground() and foreground().

### QColor QTreeWidgetItem.backgroundColor (self, int)

### Qt.CheckState QTreeWidgetItem.checkState (self, int)

Returns the check state of the label in the given column.

See also setCheckState() and Qt.CheckState.

### QTreeWidgetItem QTreeWidgetItem.child (self, int)

Returns the item at the given index in the list of the item's children.

See also parent().

### int QTreeWidgetItem.childCount (self)

Returns the number of child items.

### ChildIndicatorPolicy QTreeWidgetItem.childIndicatorPolicy (self)

Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.

See also setChildIndicatorPolicy().

### QTreeWidgetItem QTreeWidgetItem.clone (self)

Creates a deep copy of the item and of its children.

### int QTreeWidgetItem.columnCount (self)

Returns the number of columns in the item.

### QVariant QTreeWidgetItem.data (self, int, int)

Returns the value for the item's column and role.

See also setData().

### QTreeWidgetItem.emitDataChanged (self)

Causes the model associated with this item to emit a dataChanged() signal for this item.

You normally only need to call this function if you have subclassed QTreeWidgetItem and reimplemented data() and/or setData().

This function was introduced in Qt 4.5.

See also setData().

### Qt.ItemFlags QTreeWidgetItem.flags (self)

Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.

The default value for flags is Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled. If the item was constructed with a parent, flags will in addition contain Qt.ItemIsDropEnabled.

See also setFlags().

### QFont QTreeWidgetItem.font (self, int)

Returns the font used to render the text in the specified column.

See also setFont().

### QBrush QTreeWidgetItem.foreground (self, int)

Returns the brush used to render the foreground (e.g. text) of the specified column.

This function was introduced in Qt 4.2.

See also setForeground() and background().

### QIcon QTreeWidgetItem.icon (self, int)

Returns the icon that is displayed in the specified column.

See also setIcon() and iconSize.

### int QTreeWidgetItem.indexOfChild (self, QTreeWidgetItem)

Returns the index of the given child in the item's list of children.

### QTreeWidgetItem.insertChild (self, int, QTreeWidgetItem)

The QTreeWidgetItem argument has it's ownership transferred to Qt.

Inserts the child item at index in the list of children.

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

### QTreeWidgetItem.insertChildren (self, int, list-of-QTreeWidgetItem)

The list-of-QTreeWidgetItem argument has it's ownership transferred to Qt.

Inserts the given list of children into the list of the item children at index .

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

This function was introduced in Qt 4.1.

### bool QTreeWidgetItem.isDisabled (self)

Returns true if the item is disabled; otherwise returns false.

This function was introduced in Qt 4.3.

See also setFlags().

### bool QTreeWidgetItem.isExpanded (self)

Returns true if the item is expanded, otherwise returns false.

This function was introduced in Qt 4.2.

See also setExpanded().

### bool QTreeWidgetItem.isFirstColumnSpanned (self)

Returns true if the item is spanning all the columns in a row; otherwise returns false.

This function was introduced in Qt 4.3.

See also setFirstColumnSpanned().

### bool QTreeWidgetItem.isHidden (self)

Returns true if the item is hidden, otherwise returns false.

This function was introduced in Qt 4.2.

See also setHidden().

### bool QTreeWidgetItem.isSelected (self)

Returns true if the item is selected, otherwise returns false.

This function was introduced in Qt 4.2.

See also setSelected().

### QTreeWidgetItem QTreeWidgetItem.parent (self)

Returns the item's parent.

See also child().

### QTreeWidgetItem.read (self, QDataStream)

Reads the item from stream in. This only reads data into a single item.

See also write().

### QTreeWidgetItem.removeChild (self, QTreeWidgetItem)

The QTreeWidgetItem argument

Removes the given item indicated by child. The removed item will not be deleted.

### QTreeWidgetItem.setBackground (self, int, QBrush)

Sets the background brush of the label in the given column to the specified brush.

This function was introduced in Qt 4.2.

See also background() and setForeground().

### QTreeWidgetItem.setBackgroundColor (self, int, QColor)

### QTreeWidgetItem.setCheckState (self, int, Qt.CheckState)

Sets the item in the given column check state to be state.

See also checkState().

### QTreeWidgetItem.setChildIndicatorPolicy (self, ChildIndicatorPolicy)

Sets the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown. The default value is ShowForChildren.

See also childIndicatorPolicy().

### QTreeWidgetItem.setData (self, int, int, QVariant)

Sets the value for the item's column and role to the given value.

The role describes the type of data specified by value, and is defined by the Qt.ItemDataRole enum.

See also data().

### QTreeWidgetItem.setDisabled (self, bool)

Disables the item if disabled is true; otherwise enables the item.

This function was introduced in Qt 4.3.

See also isDisabled() and setFlags().

### QTreeWidgetItem.setExpanded (self, bool)

Expands the item if expand is true, otherwise collapses the item.

Warning: The QTreeWidgetItem must be added to the QTreeWidget before calling this function.

This function was introduced in Qt 4.2.

See also isExpanded().

### QTreeWidgetItem.setFirstColumnSpanned (self, bool)

Sets the first section to span all columns if span is true; otherwise all item sections are shown.

This function was introduced in Qt 4.3.

See also isFirstColumnSpanned().

### QTreeWidgetItem.setFlags (self, Qt.ItemFlags)

Sets the flags for the item to the given flags. These determine whether the item can be selected or modified. This is often used to disable an item.

See also flags().

### QTreeWidgetItem.setFont (self, int, QFont)

Sets the font used to display the text in the given column to the given font.

See also font(), setText(), and setForeground().

### QTreeWidgetItem.setForeground (self, int, QBrush)

Sets the foreground brush of the label in the given column to the specified brush.

This function was introduced in Qt 4.2.

See also foreground() and setBackground().

### QTreeWidgetItem.setHidden (self, bool)

Hides the item if hide is true, otherwise shows the item.

This function was introduced in Qt 4.2.

See also isHidden().

### QTreeWidgetItem.setIcon (self, int, QIcon)

Sets the icon to be displayed in the given column to icon.

See also icon(), setText(), and iconSize.

### QTreeWidgetItem.setSelected (self, bool)

Sets the selected state of the item to select.

This function was introduced in Qt 4.2.

See also isSelected().

### QTreeWidgetItem.setSizeHint (self, int, QSize)

Sets the size hint for the tree item in the given column to be size. If no size hint is set, the item delegate will compute the size hint based on the item data.

This function was introduced in Qt 4.1.

See also sizeHint().

### QTreeWidgetItem.setStatusTip (self, int, QString)

Sets the status tip for the given column to the given statusTip. QTreeWidget mouse tracking needs to be enabled for this feature to work.

See also statusTip(), setToolTip(), and setWhatsThis().

### QTreeWidgetItem.setText (self, int, QString)

Sets the text to be displayed in the given column to the given text.

See also text(), setFont(), and setForeground().

### QTreeWidgetItem.setTextAlignment (self, int, int)

Sets the text alignment for the label in the given column to the alignment specified (see Qt.AlignmentFlag).

See also textAlignment().

### QTreeWidgetItem.setTextColor (self, int, QColor)

### QTreeWidgetItem.setToolTip (self, int, QString)

Sets the tooltip for the given column to toolTip.

See also toolTip(), setStatusTip(), and setWhatsThis().

### QTreeWidgetItem.setWhatsThis (self, int, QString)

Sets the "What's This?" help for the given column to whatsThis.

See also whatsThis(), setStatusTip(), and setToolTip().

### QSize QTreeWidgetItem.sizeHint (self, int)

Returns the size hint set for the tree item in the given column (see QSize).

This function was introduced in Qt 4.1.

See also setSizeHint().

### QTreeWidgetItem.sortChildren (self, int, Qt.SortOrder)

Sorts the children of the item using the given order, by the values in the given column.

Note: This function does nothing if the item is not associated with a QTreeWidget.

This function was introduced in Qt 4.2.

### QString QTreeWidgetItem.statusTip (self, int)

Returns the status tip for the contents of the given column.

See also setStatusTip().

### QTreeWidgetItem QTreeWidgetItem.takeChild (self, int)

The QTreeWidgetItem result

Removes the item at index and returns it, otherwise return 0.

### list-of-QTreeWidgetItem QTreeWidgetItem.takeChildren (self)

The list-of-QTreeWidgetItem result

Removes the list of children and returns it, otherwise returns an empty list.

This function was introduced in Qt 4.1.

### QString QTreeWidgetItem.text (self, int)

Returns the text in the specified column.

See also setText().

### int QTreeWidgetItem.textAlignment (self, int)

Returns the text alignment for the label in the given column (see Qt.AlignmentFlag).

See also setTextAlignment().

### QColor QTreeWidgetItem.textColor (self, int)

### QString QTreeWidgetItem.toolTip (self, int)

Returns the tool tip for the given column.

See also setToolTip().

### QTreeWidget QTreeWidgetItem.treeWidget (self)

Returns the tree widget that contains the item.

### int QTreeWidgetItem.type (self)

Returns the type passed to the QTreeWidgetItem constructor.

### QString QTreeWidgetItem.whatsThis (self, int)

Returns the "What's This?" help for the contents of the given column.

See also setWhatsThis().

### QTreeWidgetItem.write (self, QDataStream)

Writes the item to stream out. This only writes data from one single item.

See also read().

### bool QTreeWidgetItem.__ge__ (self, QTreeWidgetItem)

### bool QTreeWidgetItem.__lt__ (self, QTreeWidgetItem)