Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QTreeWidgetItem Class Reference

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

    #include <QTreeWidgetItem>

- List of all members, including inherited members

### Public Functions

- QTreeWidgetItem ( QTreeWidget * view )
- QTreeWidgetItem ( QTreeWidget * view, QTreeWidgetItem * preceding )
- QTreeWidgetItem ( QTreeWidgetItem * parent )
- QTreeWidgetItem ( QTreeWidgetItem * parent, QTreeWidgetItem * preceding )
- virtual ~QTreeWidgetItem ()
- void appendChild ( QTreeWidgetItem * child )
- QColor backgroundColor ( int column ) const
- int checkedState ( int column ) const
- QTreeWidgetItem * child ( int index ) const
- int childCount () const
- virtual void clear ()
- int columnCount () const
- virtual QVariant data ( int column, int role ) const
- QAbstractItemModel::ItemFlags flags () const
- QFont font ( int column ) const
- QIcon icon ( int column ) const
- int indexOfChild ( QTreeWidgetItem * child ) const
- void insertChild ( int index, QTreeWidgetItem * child )
- QTreeWidgetItem * parent () const
- void setBackgroundColor ( int column, const QColor & color )
- void setCheckedState ( int column, bool state )
- virtual void setData ( int column, int role, const QVariant & value )
- void setFlags ( QAbstractItemModel::ItemFlags flags )
- void setFont ( int column, const QFont & font )
- void setIcon ( int column, const QIcon & icon )
- void setStatusTip ( int column, const QString & statusTip )
- void setText ( int column, const QString & text )
- void setTextAlignment ( int column, int alignment )
- void setTextColor ( int column, const QColor & color )
- void setToolTip ( int column, const QString & toolTip )
- void setWhatsThis ( int column, const QString & whatsThis )
- QString statusTip ( int column ) const
- QTreeWidgetItem * takeChild ( int index )
- QString text ( int column ) const
- int textAlignment ( int column ) const
- QColor textColor ( int column ) const
- QString toolTip ( int column ) const
- QTreeWidget * treeWidget () const
- QString whatsThis ( int column ) const
- virtual bool operator< ( const QTreeWidgetItem & other ) const

### Protected Functions

- void sortChildren ( int column, Qt::SortOrder order, bool climb )

## 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 color which is set with the setBackgroundColor() function. The current background color can be found with backgroundColor(). The text label for each column can be rendered with its own font and text color. These are specified with the setFont() and setTextColor() functions, and read with font() and textColor().

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.

See also QTreeWidget.

## Member Function Documentation

### QTreeWidgetItem::QTreeWidgetItem ( QTreeWidget * view )

Constructs a tree widget item and appends it into the given tree view.

### QTreeWidgetItem::QTreeWidgetItem ( QTreeWidget * view, QTreeWidgetItem * preceding )

Constructs a tree widget item and inserts it into the given tree view after the preceding item.

### QTreeWidgetItem::QTreeWidgetItem ( QTreeWidgetItem * parent )

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

### QTreeWidgetItem::QTreeWidgetItem ( QTreeWidgetItem * parent, QTreeWidgetItem * preceding )

Constructs a tree widget item with the given parent that is inserted into the parent's list of child items after the preceding child.

### QTreeWidgetItem::~QTreeWidgetItem () `[virtual]`

Destroys this tree widget item.

### void QTreeWidgetItem::appendChild ( QTreeWidgetItem * child )

Appends the child item to the list of children.

See also insertChild() and takeChild().

### QColor QTreeWidgetItem::backgroundColor ( int column ) const

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

See also textColor() and setBackgroundColor().

### int QTreeWidgetItem::checkedState ( int column ) const

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

See also QCheckBox::ToggleState.

### QTreeWidgetItem * QTreeWidgetItem::child ( int index ) const

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

See also parent().

### int QTreeWidgetItem::childCount () const

Returns the number of child items.

### void QTreeWidgetItem::clear () `[virtual]`

Removes all item data.

### int QTreeWidgetItem::columnCount () const

Returns the number of columns in the item.

### QVariant QTreeWidgetItem::data ( int column, int role ) const `[virtual]`

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

### QAbstractItemModel::ItemFlags QTreeWidgetItem::flags () const

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

See also setFlags().

### QFont QTreeWidgetItem::font ( int column ) const

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

See also setFont().

### QIcon QTreeWidgetItem::icon ( int column ) const

Returns the icon that is displayed in the specified column.

See also setIcon().

### int QTreeWidgetItem::indexOfChild ( QTreeWidgetItem * child ) const

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

### void QTreeWidgetItem::insertChild ( int index, QTreeWidgetItem * child )

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

### QTreeWidgetItem * QTreeWidgetItem::parent () const

Returns the item's parent.

See also child().

### void QTreeWidgetItem::setBackgroundColor ( int column, const QColor & color )

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

See also backgroundColor() and setTextColor().

### void QTreeWidgetItem::setCheckedState ( int column, bool state )

If state is true, the label in the given column is checked; otherwise it is unchecked. The item must be checkable for this function to have an effect.

See also checkedState() and QAbstractItemModel::ItemFlag.

### void QTreeWidgetItem::setData ( int column, int role, const QVariant & value ) `[virtual]`

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

### void QTreeWidgetItem::setFlags ( QAbstractItemModel::ItemFlags flags )

Sets the flags for the item to the given flags. These determine whether the item can be selected or modified.

See also flags().

### void QTreeWidgetItem::setFont ( int column, const QFont & font )

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

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

### void QTreeWidgetItem::setIcon ( int column, const QIcon & icon )

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

See also icon() and setText().

### void QTreeWidgetItem::setStatusTip ( int column, const QString & statusTip )

Sets the status tip for the given column to the given statusTip.

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

### void QTreeWidgetItem::setText ( int column, const QString & text )

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

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

### void QTreeWidgetItem::setTextAlignment ( int column, int alignment )

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

### void QTreeWidgetItem::setTextColor ( int column, const QColor & color )

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

See also textColor(), setFont(), and setText().

### void QTreeWidgetItem::setToolTip ( int column, const QString & toolTip )

Sets the tooltip for the given column to toolTip.

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

### void QTreeWidgetItem::setWhatsThis ( int column, const QString & whatsThis )

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

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

### void QTreeWidgetItem::sortChildren ( int column, Qt::SortOrder order, bool climb ) `[protected]`

Sorts the children by the value in the given column, in the order specified. If climb is true, the items below each of the children will also be sorted.

### QString QTreeWidgetItem::statusTip ( int column ) const

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

See also setStatusTip().

### QTreeWidgetItem * QTreeWidgetItem::takeChild ( int index )

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

### QString QTreeWidgetItem::text ( int column ) const

Returns the text in the specified column.

See also setText().

### int QTreeWidgetItem::textAlignment ( int column ) const

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

### QColor QTreeWidgetItem::textColor ( int column ) const

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

See also backgroundColor() and setTextColor().

### QString QTreeWidgetItem::toolTip ( int column ) const

Returns the tool tip for the given column.

See also setToolTip().

### QTreeWidget * QTreeWidgetItem::treeWidget () const

Returns the tree widget that contains the item.

### QString QTreeWidgetItem::whatsThis ( int column ) const

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

See also setWhatsThis().

### bool QTreeWidgetItem::operator< ( const QTreeWidgetItem & other ) const `[virtual]`

Returns true if the text in the item is less than the text in the other item, otherwise returns false.