QTreeWidgetItem Class Reference

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

  1. #include <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:

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

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

  1.     QTreeWidgetItem *planets = new QTreeWidgetItem(treeWidget, cities);
  2.     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.

Public Types

Toggle detailsenum QTreeWidgetItem::

ChildIndicatorPolicyChildIndicatorPolicy { ShowIndicator , DontShowIndicator , DontShowIndicatorWhenChildless 2 ...} { ShowIndicator , DontShowIndicator , DontShowIndicatorWhenChildless 2 }

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

Look up this member in the source code.

Toggle detailsenum QTreeWidgetItem::

ItemTypeItemType { Type , UserType 1000 ...} { Type , UserType 1000 }

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

ConstantValueDescription
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().

Look up this member in the source code.

    Public Functions

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( int type=Type ) ( int type=Type )

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

    See also type().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( const QStringList &strings , int type=Type ...) ( const QStringList &strings , int type=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().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( QTreeWidget *parent , int type=Type ...) ( QTreeWidget *parent , int type=Type )

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

    See also type().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( QTreeWidget *parent , const QStringList &strings , int type=Type ...) ( QTreeWidget *parent , const QStringList &strings , int type=Type )

    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().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( QTreeWidget *parent , QTreeWidgetItem *preceding , int type=Type ...) ( QTreeWidget *parent , QTreeWidgetItem *preceding , int type=Type )

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

    See also type().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( QTreeWidgetItem *parent , int type=Type ...) ( QTreeWidgetItem *parent , int type=Type )

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

    See also type().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( QTreeWidgetItem *parent , const QStringList &strings , int type=Type ...) ( QTreeWidgetItem *parent , const QStringList &strings , int type=Type )

    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().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( QTreeWidgetItem *parent , QTreeWidgetItem *preceding , int type=Type ...) ( QTreeWidgetItem *parent , QTreeWidgetItem *preceding , int type=Type )

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

    See also type().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    QTreeWidgetItemQTreeWidgetItem ( const QTreeWidgetItem &other ) ( const QTreeWidgetItem &other )

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

    This function is useful when reimplementing clone().

    See also data() and flags().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem

    ~QTreeWidgetItem~QTreeWidgetItem () () [virtual]

    Destroys this tree widget item.

    The item will be removed from QTreeWidgets to which it has been added. This makes it safe to delete an item at any time.

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    addChildaddChild ( QTreeWidgetItem *child ) ( QTreeWidgetItem *child )

    Appends the child item to the list of children.

    See also insertChild() and takeChild().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    addChildrenaddChildren ( const QList <QTreeWidgetItem *> &children ...) ( const QList <QTreeWidgetItem *> &children )

    Appends the given list of children to the item.

    See also insertChildren() and takeChildren().

    Look up this member in the source code.

    Toggle details QBrush QTreeWidgetItem

    backgroundbackground ( int column ) ( int column )const

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

    See also setBackground() and foreground().

    Look up this member in the source code.

    Toggle details Qt::CheckState QTreeWidgetItem

    checkStatecheckState ( int column ) ( int column )const

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

    See also setCheckState() and Qt::CheckState.

    Look up this member in the source code.

    Toggle details QTreeWidgetItem * QTreeWidgetItem

    childchild ( int index ) ( int index )const

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

    See also parent().

    Look up this member in the source code.

    Toggle details int QTreeWidgetItem

    childCountchildCount () ()const

    Returns the number of child items.

    Look up this member in the source code.

    Toggle details QTreeWidgetItem::ChildIndicatorPolicy QTreeWidgetItem

    childIndicatorPolicychildIndicatorPolicy (...) ()const

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

    See also setChildIndicatorPolicy().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem * QTreeWidgetItem

    cloneclone () ()const [virtual]

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

    Look up this member in the source code.

    Toggle details int QTreeWidgetItem

    columnCountcolumnCount () ()const

    Returns the number of columns in the item.

    Look up this member in the source code.

    Toggle details QVariant QTreeWidgetItem

    datadata ( int column , int role ) ( int column , int role )const [virtual]

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

    See also setData().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    emitDataChangedemitDataChanged () ()[protected]

    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().

    See also setData().

    Look up this member in the source code.

    Toggle details Qt::ItemFlags QTreeWidgetItem

    flagsflags () ()const

    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().

    Look up this member in the source code.

    Toggle details QFont QTreeWidgetItem

    fontfont ( int column ) ( int column )const

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

    See also setFont().

    Look up this member in the source code.

    Toggle details QBrush QTreeWidgetItem

    foregroundforeground ( int column ) ( int column )const

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

    See also setForeground() and background().

    Look up this member in the source code.

    Toggle details QIcon QTreeWidgetItem

    iconicon ( int column ) ( int column )const

    Returns the icon that is displayed in the specified column.

    See also setIcon() and iconSize.

    Look up this member in the source code.

    Toggle details int QTreeWidgetItem

    indexOfChildindexOfChild ( QTreeWidgetItem *child ) ( QTreeWidgetItem *child )const

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

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    insertChildinsertChild ( int index , QTreeWidgetItem *child ...) ( int index , QTreeWidgetItem *child )

    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.

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    insertChildreninsertChildren ( int index , const QList <QTreeWidgetItem *> &children ...) ( int index , const QList <QTreeWidgetItem *> &children )

    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.

    Look up this member in the source code.

    Toggle details bool QTreeWidgetItem

    isDisabledisDisabled () ()const

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

    See also setFlags().

    Look up this member in the source code.

    Toggle details bool QTreeWidgetItem

    isExpandedisExpanded () ()const

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

    See also setExpanded().

    Look up this member in the source code.

    Toggle details bool QTreeWidgetItem

    isFirstColumnSpannedisFirstColumnSpanned () ()const

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

    See also setFirstColumnSpanned().

    Look up this member in the source code.

    Toggle details bool QTreeWidgetItem

    isHiddenisHidden () ()const

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

    See also setHidden().

    Look up this member in the source code.

    Toggle details bool QTreeWidgetItem

    isSelectedisSelected () ()const

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

    See also setSelected().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem * QTreeWidgetItem

    parentparent () ()const

    Returns the item's parent.

    See also child().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    readread ( QDataStream &in ) ( QDataStream &in ) [virtual]

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

    See also write().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    removeChildremoveChild ( QTreeWidgetItem *child ) ( QTreeWidgetItem *child )

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

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setBackgroundsetBackground ( int column , const QBrush &brush ...) ( int column , const QBrush &brush )

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

    See also background() and setForeground().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setCheckStatesetCheckState ( int column , Qt::CheckState state ...) ( int column , Qt::CheckState state )

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

    See also checkState().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setChildIndicatorPolicysetChildIndicatorPolicy ( QTreeWidgetItem::ChildIndicatorPolicy policy ...) ( QTreeWidgetItem::ChildIndicatorPolicy policy )

    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().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setDatasetData ( int column , int role , const QVariant &value ...) ( int column , int role , const QVariant &value ) [virtual]

    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().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setDisabledsetDisabled ( bool disabled ) ( bool disabled )

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

    See also isDisabled() and setFlags().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setExpandedsetExpanded ( bool expand ) ( bool expand )

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

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

    See also isExpanded().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setFirstColumnSpannedsetFirstColumnSpanned ( bool span ) ( bool span )

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

    See also isFirstColumnSpanned().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setFlagssetFlags ( Qt::ItemFlags flags ) ( Qt::ItemFlags flags )

    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().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setFontsetFont ( int column , const QFont &font ) ( 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 setForeground().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setForegroundsetForeground ( int column , const QBrush &brush ...) ( int column , const QBrush &brush )

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

    See also foreground() and setBackground().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setHiddensetHidden ( bool hide ) ( bool hide )

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

    See also isHidden().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setIconsetIcon ( int column , const QIcon &icon ) ( int column , const QIcon &icon )

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

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

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setSelectedsetSelected ( bool select ) ( bool select )

    Sets the selected state of the item to select.

    See also isSelected().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setSizeHintsetSizeHint ( int column , const QSize &size ) ( int column , const QSize &size )

    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.

    See also sizeHint().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setStatusTipsetStatusTip ( int column , const QString &statusTip ...) ( int column , const QString &statusTip )

    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().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setTextsetText ( int column , const QString &text ) ( int column , const QString &text )

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

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

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setTextAlignmentsetTextAlignment ( int column , int alignment ) ( int column , int alignment )

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

    See also textAlignment().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setToolTipsetToolTip ( int column , const QString &toolTip ...) ( int column , const QString &toolTip )

    Sets the tooltip for the given column to toolTip.

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

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setWhatsThissetWhatsThis ( int column , const QString &whatsThis ...) ( int column , const QString &whatsThis )

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

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

    Look up this member in the source code.

    Toggle details QSize QTreeWidgetItem

    sizeHintsizeHint ( int column ) ( int column )const

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

    See also setSizeHint().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    sortChildrensortChildren ( int column , Qt::SortOrder order ( int column , Qt::SortOrder order )

    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.

    Look up this member in the source code.

    Toggle details QString QTreeWidgetItem

    statusTipstatusTip ( int column ) ( int column )const

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

    See also setStatusTip().

    Look up this member in the source code.

    Toggle details QTreeWidgetItem * QTreeWidgetItem

    takeChildtakeChild ( int index ) ( int index )

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

    Look up this member in the source code.

    Toggle details QList <QTreeWidgetItem *> QTreeWidgetItem

    takeChildrentakeChildren () ()

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

    Look up this member in the source code.

    Toggle details QString QTreeWidgetItem

    texttext ( int column ) ( int column )const

    Returns the text in the specified column.

    See also setText().

    Look up this member in the source code.

    Toggle details int QTreeWidgetItem

    textAlignmenttextAlignment ( int column ) ( int column )const

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

    See also setTextAlignment().

    Look up this member in the source code.

    Toggle details QString QTreeWidgetItem

    toolTiptoolTip ( int column ) ( int column )const

    Returns the tool tip for the given column.

    See also setToolTip().

    Look up this member in the source code.

    Toggle details QTreeWidget * QTreeWidgetItem

    treeWidgettreeWidget () ()const

    Returns the tree widget that contains the item.

    Look up this member in the source code.

    Toggle details int QTreeWidgetItem

    typetype () ()const

    Returns the type passed to the QTreeWidgetItem constructor.

    Look up this member in the source code.

    Toggle details QString QTreeWidgetItem

    whatsThiswhatsThis ( int column ) ( int column )const

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

    See also setWhatsThis().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    writewrite ( QDataStream &out ) ( QDataStream &out )const [virtual]

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

    See also read().

    Look up this member in the source code.

    Toggle details bool QTreeWidgetItem

    operator<operator< ( const QTreeWidgetItem &other ) ( 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.

    Look up this member in the source code.

    Toggle details QTreeWidgetItem & QTreeWidgetItem

    operator=operator= ( const QTreeWidgetItem &other ...) ( const QTreeWidgetItem &other )

    Assigns other's data and flags to this item. Note that type() and treeWidget() are not copied.

    This function is useful when reimplementing clone().

    See also data() and flags().

    Look up this member in the source code.

    Toggle details QColor QTreeWidgetItem

    backgroundColorbackgroundColor ( int column ) ( int column )const Obsolete function

    This function is deprecated. Use background() instead.

    See also setBackgroundColor().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setBackgroundColorsetBackgroundColor ( int column , const QColor &color ...) ( int column , const QColor &color ) Obsolete function

    This function is deprecated. Use setBackground() instead.

    See also backgroundColor().

    Look up this member in the source code.

    Toggle details void QTreeWidgetItem

    setTextColorsetTextColor ( int column , const QColor &color ( int column , const QColor &color ) Obsolete function

    This function is deprecated. Use setForeground() instead.

    See also textColor().

    Look up this member in the source code.

    Toggle details QColor QTreeWidgetItem

    textColortextColor ( int column ) ( int column )const Obsolete function

    This function is deprecated. Use foreground() instead.

    See also setTextColor().

    Look up this member in the source code.

    Notes provided by the Qt Community

    No notes