Qt Jambi Home

com.trolltech.qt.gui
Class QTreeWidgetItem

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.gui.QTreeWidgetItem
All Implemented Interfaces:
QtJambiInterface

public class QTreeWidgetItem
extends QtJambiObject

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, Model/View Programming, QListWidgetItem, QTableWidgetItem

Nested Class Summary
static class QTreeWidgetItem.ChildIndicatorPolicy
          Press link for info on QTreeWidgetItem.ChildIndicatorPolicy
static class QTreeWidgetItem.ItemType
          This enum describes the types that are used to describe tree widget items.
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QTreeWidgetItem()
          Equivalent to QTreeWidgetItem(Type).
QTreeWidgetItem(int type)
          Constructs a tree widget item of the specified type.
QTreeWidgetItem(java.util.List<java.lang.String> strings)
          Equivalent to QTreeWidgetItem(strings, Type).
QTreeWidgetItem(java.util.List<java.lang.String> strings, int type)
          Constructs a tree widget item of the specified type.
QTreeWidgetItem(QTreeWidget view)
          Equivalent to QTreeWidgetItem(view, Type).
QTreeWidgetItem(QTreeWidget view, int type)
          Constructs a tree widget item of the specified type and appends it to the items in the given view.
QTreeWidgetItem(QTreeWidgetItem parent)
          Equivalent to QTreeWidgetItem(parent, Type).
QTreeWidgetItem(QTreeWidgetItem parent, int type)
          Constructs a tree widget item and append it to the given parent.
QTreeWidgetItem(QTreeWidgetItem parent, java.util.List<java.lang.String> strings)
          Equivalent to QTreeWidgetItem(parent, strings, Type).
QTreeWidgetItem(QTreeWidgetItem parent, java.util.List<java.lang.String> strings, int type)
          Constructs a tree widget item and append it to the given parent.
QTreeWidgetItem(QTreeWidgetItem parent, QTreeWidgetItem after)
          Equivalent to QTreeWidgetItem(parent, after, Type).
QTreeWidgetItem(QTreeWidgetItem parent, QTreeWidgetItem after, int type)
          Constructs a tree widget item of the specified type that is inserted into the parent after the after child item.
QTreeWidgetItem(QTreeWidget view, java.util.List<java.lang.String> strings)
          Equivalent to QTreeWidgetItem(view, strings, Type).
QTreeWidgetItem(QTreeWidget view, java.util.List<java.lang.String> strings, int type)
          Constructs a tree widget item of the specified type and appends it to the items in the given view.
QTreeWidgetItem(QTreeWidget view, QTreeWidgetItem after)
          Equivalent to QTreeWidgetItem(view, after, Type).
QTreeWidgetItem(QTreeWidget view, QTreeWidgetItem after, int type)
          Constructs a tree widget item of the specified type and inserts it into the given view after the after item.
 
Method Summary
 void addChild(QTreeWidgetItem child)
          Appends the child item to the list of children.
 void addChildren(java.util.List<QTreeWidgetItem> children)
          Appends the given list of children to the item.
 QBrush background(int column)
          Returns the brush used to render the background of the specified column.
 Qt.CheckState checkState(int column)
          Returns the check state of the label in the given column.
 QTreeWidgetItem child(int index)
          Returns the item at the given index in the list of the item's children.
 int childCount()
          Returns the number of child items.
 QTreeWidgetItem.ChildIndicatorPolicy childIndicatorPolicy()
          Returns the item indicator policy.
 QTreeWidgetItem clone()
          Creates a deep copy of the item and of its children.
 int columnCount()
          Returns the number of columns in the item.
 java.lang.Object data(int column, int role)
          Returns the value for the item's column and role.
 Qt.ItemFlags flags()
          Returns the flags used to describe the item.
 QFont font(int column)
          Returns the font used to render the text in the specified column.
 QBrush foreground(int column)
          Returns the brush used to render the foreground (e.g. text) of the specified column.
static QTreeWidgetItem fromNativePointer(QNativePointer nativePointer)
          This function returns the QTreeWidgetItem instance pointed to by nativePointer
 QIcon icon(int column)
          Returns the icon that is displayed in the specified column.
 int indexOfChild(QTreeWidgetItem child)
          Returns the index of the given child in the item's list of children.
 void insertChild(int index, QTreeWidgetItem child)
          Inserts the child item at index in the list of children.
 void insertChildren(int index, java.util.List<QTreeWidgetItem> children)
          Inserts the given list of children into the list of the item children at index .
 boolean isDisabled()
          Returns true if the item is disabled; otherwise returns false.
 boolean isExpanded()
          Returns true if the item is expanded, otherwise returns false.
 boolean isFirstColumnSpanned()
          Returns true if the item is spanning all the columns in a row; otherwise returns false.
 boolean isHidden()
          Returns true if the item is hidden, otherwise returns false.
 boolean isSelected()
          Returns true if the item is selected, otherwise returns false.
 QTreeWidgetItem parent()
          Returns the item's parent.
 void read(QDataStream in)
          Reads the item from stream in.
 void readFrom(QDataStream in)
          Reads a QTreeWidgetItem from in.
 void removeChild(QTreeWidgetItem child)
          Removes the given item indicated by child.
 void setBackground(int column, QBrush brush)
          Sets the background brush of the label in the given column to the specified brush.
 void setCheckState(int column, Qt.CheckState state)
          Sets the item in the given column check state to be state.
 void setChildIndicatorPolicy(QTreeWidgetItem.ChildIndicatorPolicy policy)
          Sets the item indicator policy.
 void setData(int column, int role, java.lang.Object value)
          Sets the value for the item's column and role to the given value.
 void setDisabled(boolean disabled)
          Disables the item if disabled is true; otherwise enables the item.
 void setExpanded(boolean expand)
          Expands the item if expand is true, otherwise collapses the item.
 void setFirstColumnSpanned(boolean span)
          Sets the first section to span all columns if span is true; otherwise all item sections are shown.
 void setFlags(Qt.ItemFlag... flags)
          Sets the flags for the item to the given flags.
 void setFlags(Qt.ItemFlags flags)
          Sets the flags for the item to the given flags.
 void setFont(int column, QFont font)
          Sets the font used to display the text in the given column to the given font.
 void setForeground(int column, QBrush brush)
          Sets the foreground brush of the label in the given column to the specified brush.
 void setHidden(boolean hide)
          Hides the item if hide is true, otherwise shows the item.
 void setIcon(int column, QIcon icon)
          Sets the icon to be displayed in the given column to icon.
 void setSelected(boolean select)
          Sets the selected state of the item to select.
 void setSizeHint(int column, QSize size)
          Sets the size hint for the tree item in the given column to be size.
 void setStatusTip(int column, java.lang.String statusTip)
          Sets the status tip for the given column to the given statusTip.
 void setText(int column, java.lang.String text)
          Sets the text to be displayed in the given column to the given text.
 void setTextAlignment(int column, int alignment)
          Sets the text alignment for the label in the given column to the alignment specified (see Qt::AlignmentFlag).
 void setToolTip(int column, java.lang.String toolTip)
          Sets the tooltip for the given column to toolTip.
 void setWhatsThis(int column, java.lang.String whatsThis)
          Sets the "What's This?" help for the given column to whatsThis.
 QSize sizeHint(int column)
          Returns the size hint set for the tree item in the given column (see QSize).
 void sortChildren(int column, Qt.SortOrder order)
          Sorts the children of the item using the given order, by the values in the given column.
 java.lang.String statusTip(int column)
          Returns the status tip for the contents of the given column.
 QTreeWidgetItem takeChild(int index)
          Removes the item at index and returns it, otherwise return 0.
 java.util.List<QTreeWidgetItem> takeChildren()
          Removes the list of children and returns it, otherwise returns an empty list.
 java.lang.String text(int column)
          Returns the text in the specified column.
 int textAlignment(int column)
          Returns the text alignment for the label in the given column (see Qt::AlignmentFlag).
 java.lang.String toolTip(int column)
          Returns the tool tip for the given column.
 QTreeWidget treeWidget()
          Returns the tree widget that contains the item.
 int type()
          Returns the type passed to the QTreeWidgetItem constructor.
 java.lang.String whatsThis(int column)
          Returns the "What's This?" help for the contents of the given column.
 void write(QDataStream out)
          Writes the item to stream out.
 void writeTo(QDataStream out)
          Writes thisQTreeWidgetItem to out.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QTreeWidgetItem

public QTreeWidgetItem(java.util.List<java.lang.String> strings)

Equivalent to QTreeWidgetItem(strings, Type).


QTreeWidgetItem

public QTreeWidgetItem(java.util.List<java.lang.String> strings,
                       int 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

public QTreeWidgetItem(QTreeWidget view,
                       java.util.List<java.lang.String> strings)

Equivalent to QTreeWidgetItem(view, strings, Type).


QTreeWidgetItem

public QTreeWidgetItem(QTreeWidget view,
                       java.util.List<java.lang.String> strings,
                       int type)

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

See Also:
type

QTreeWidgetItem

public QTreeWidgetItem(QTreeWidgetItem parent,
                       java.util.List<java.lang.String> strings)

Equivalent to QTreeWidgetItem(parent, strings, Type).


QTreeWidgetItem

public QTreeWidgetItem(QTreeWidgetItem parent,
                       java.util.List<java.lang.String> strings,
                       int 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

QTreeWidgetItem

public QTreeWidgetItem(QTreeWidget view,
                       QTreeWidgetItem after)

Equivalent to QTreeWidgetItem(view, after, Type).


QTreeWidgetItem

public QTreeWidgetItem(QTreeWidget view,
                       QTreeWidgetItem after,
                       int type)

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

See Also:
type

QTreeWidgetItem

public QTreeWidgetItem(QTreeWidgetItem parent,
                       QTreeWidgetItem after)

Equivalent to QTreeWidgetItem(parent, after, Type).


QTreeWidgetItem

public QTreeWidgetItem(QTreeWidgetItem parent,
                       QTreeWidgetItem after,
                       int type)

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

See Also:
type

QTreeWidgetItem

public QTreeWidgetItem()

Equivalent to QTreeWidgetItem(Type).


QTreeWidgetItem

public QTreeWidgetItem(int type)

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

See Also:
type

QTreeWidgetItem

public QTreeWidgetItem(QTreeWidgetItem parent)

Equivalent to QTreeWidgetItem(parent, Type).


QTreeWidgetItem

public QTreeWidgetItem(QTreeWidgetItem parent,
                       int type)

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

See Also:
type

QTreeWidgetItem

public QTreeWidgetItem(QTreeWidget view)

Equivalent to QTreeWidgetItem(view, Type).


QTreeWidgetItem

public QTreeWidgetItem(QTreeWidget view,
                       int type)

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

See Also:
type
Method Detail

addChild

public final void addChild(QTreeWidgetItem child)

Appends the child item to the list of children.

See Also:
insertChild, takeChild

addChildren

public final void addChildren(java.util.List<QTreeWidgetItem> children)

Appends the given list of children to the item.

See Also:
insertChildren, takeChildren

background

public final QBrush background(int column)

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

See Also:
setBackground, foreground

checkState

public final Qt.CheckState checkState(int column)

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

See Also:
setCheckState, Qt::CheckState

child

public final QTreeWidgetItem child(int index)

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

See Also:
parent

childCount

public final int childCount()

Returns the number of child items.


childIndicatorPolicy

public final QTreeWidgetItem.ChildIndicatorPolicy childIndicatorPolicy()

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

See Also:
setChildIndicatorPolicy

columnCount

public final int columnCount()

Returns the number of columns in the item.


flags

public final Qt.ItemFlags flags()

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

font

public final QFont font(int column)

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

See Also:
setFont

foreground

public final QBrush foreground(int column)

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

See Also:
setForeground, background

icon

public final QIcon icon(int column)

Returns the icon that is displayed in the specified column.

See Also:
setIcon, iconSize

indexOfChild

public final int indexOfChild(QTreeWidgetItem child)

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


insertChild

public final void insertChild(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.


insertChildren

public final void insertChildren(int index,
                                 java.util.List<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.


isDisabled

public final boolean isDisabled()

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

See Also:
setFlags

isExpanded

public final boolean isExpanded()

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

See Also:
setExpanded

isFirstColumnSpanned

public final boolean isFirstColumnSpanned()

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

See Also:
setFirstColumnSpanned

isHidden

public final boolean isHidden()

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

See Also:
setHidden

isSelected

public final boolean isSelected()

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

See Also:
setSelected

writeTo

public final void writeTo(QDataStream out)
Writes thisQTreeWidgetItem to out.


readFrom

public final void readFrom(QDataStream in)
Reads a QTreeWidgetItem from in.


parent

public final QTreeWidgetItem parent()

Returns the item's parent.

See Also:
child

removeChild

public final void removeChild(QTreeWidgetItem child)

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


setBackground

public final void setBackground(int column,
                                QBrush brush)

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

See Also:
background, setForeground

setCheckState

public final void setCheckState(int column,
                                Qt.CheckState state)

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

See Also:
checkState

setChildIndicatorPolicy

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

setDisabled

public final void setDisabled(boolean disabled)

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

See Also:
isDisabled, setFlags

setExpanded

public final void setExpanded(boolean 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

setFirstColumnSpanned

public final void setFirstColumnSpanned(boolean span)

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

See Also:
isFirstColumnSpanned

setFlags

public final void setFlags(Qt.ItemFlag... 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

setFlags

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

setFont

public final void setFont(int column,
                          QFont font)

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

See Also:
font, setText, setForeground

setForeground

public final void setForeground(int column,
                                QBrush brush)

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

See Also:
foreground, setBackground

setHidden

public final void setHidden(boolean hide)

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

See Also:
isHidden

setIcon

public final void setIcon(int column,
                          QIcon icon)

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

See Also:
icon, setText, iconSize

setSelected

public final void setSelected(boolean select)

Sets the selected state of the item to select.

See Also:
isSelected

setSizeHint

public final void setSizeHint(int column,
                              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

setStatusTip

public final void setStatusTip(int column,
                               java.lang.String 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, setWhatsThis

setText

public final void setText(int column,
                          java.lang.String text)

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

See Also:
text, setFont, setForeground

setTextAlignment

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

setToolTip

public final void setToolTip(int column,
                             java.lang.String toolTip)

Sets the tooltip for the given column to toolTip.

See Also:
toolTip, setStatusTip, setWhatsThis

setWhatsThis

public final void setWhatsThis(int column,
                               java.lang.String whatsThis)

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

See Also:
whatsThis, setStatusTip, setToolTip

sizeHint

public final QSize sizeHint(int column)

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

See Also:
setSizeHint

sortChildren

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

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


statusTip

public final java.lang.String statusTip(int column)

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

See Also:
setStatusTip

takeChild

public final QTreeWidgetItem takeChild(int index)

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


takeChildren

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

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


text

public final java.lang.String text(int column)

Returns the text in the specified column.

See Also:
setText

textAlignment

public final int textAlignment(int column)

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

See Also:
setTextAlignment

toolTip

public final java.lang.String toolTip(int column)

Returns the tool tip for the given column.

See Also:
setToolTip

treeWidget

public final QTreeWidget treeWidget()

Returns the tree widget that contains the item.


type

public final int type()

Returns the type passed to the QTreeWidgetItem constructor.


whatsThis

public final java.lang.String whatsThis(int column)

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

See Also:
setWhatsThis

clone

public QTreeWidgetItem clone()

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

Overrides:
clone in class java.lang.Object

data

public java.lang.Object data(int column,
                             int role)

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

See Also:
setData

read

public void read(QDataStream in)

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

See Also:
write

setData

public void setData(int column,
                    int role,
                    java.lang.Object value)

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

write

public void write(QDataStream out)

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

See Also:
read

fromNativePointer

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

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

Qt Jambi Home