CopperSpice API  1.9.1
QTreeWidgetItem Class Reference

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

Public Types

enum  ChildIndicatorPolicy
 
enum  ItemType
 

Public Methods

 QTreeWidgetItem (const QStringList &strings, int type=Type)
 
 QTreeWidgetItem (const QTreeWidgetItem &other)
 
 QTreeWidgetItem (int type=Type)
 
 QTreeWidgetItem (QTreeWidget *view, const QStringList &strings, int type=Type)
 
 QTreeWidgetItem (QTreeWidget *view, int type=Type)
 
 QTreeWidgetItem (QTreeWidget *view, QTreeWidgetItem *previous, int type=Type)
 
 QTreeWidgetItem (QTreeWidgetItem *parent, const QStringList &strings, int type=Type)
 
 QTreeWidgetItem (QTreeWidgetItem *parent, int type=Type)
 
 QTreeWidgetItem (QTreeWidgetItem *parent, QTreeWidgetItem *previous, int type=Type)
 
virtual ~QTreeWidgetItem ()
 
void addChild (QTreeWidgetItem *child)
 
void addChildren (const QList< QTreeWidgetItem * > &children)
 
QBrush background (int column) const
 
QColor backgroundColor (int column) const
 
Qt::CheckState checkState (int column) const
 
QTreeWidgetItem * child (int index) const
 
int childCount () const
 
QTreeWidgetItem::ChildIndicatorPolicy childIndicatorPolicy () const
 
virtual QTreeWidgetItem * clone () const
 
int columnCount () const
 
virtual QVariant data (int column, int role) const
 
Qt::ItemFlags flags () const
 
QFont font (int column) const
 
QBrush foreground (int column) const
 
QIcon icon (int column) const
 
int indexOfChild (QTreeWidgetItem *child) const
 
void insertChild (int index, QTreeWidgetItem *child)
 
void insertChildren (int index, const QList< QTreeWidgetItem * > &children)
 
bool isDisabled () const
 
bool isExpanded () const
 
bool isFirstColumnSpanned () const
 
bool isHidden () const
 
bool isSelected () const
 
virtual bool operator< (const QTreeWidgetItem &other) const
 
QTreeWidgetItem & operator= (const QTreeWidgetItem &other)
 
QTreeWidgetItem * parent () const
 
virtual void read (QDataStream &in)
 
void removeChild (QTreeWidgetItem *child)
 
void setBackground (int column, const QBrush &brush)
 
void setBackgroundColor (int column, const QColor &color)
 
void setCheckState (int column, Qt::CheckState state)
 
void setChildIndicatorPolicy (QTreeWidgetItem::ChildIndicatorPolicy policy)
 
virtual void setData (int column, int role, const QVariant &value)
 
void setDisabled (bool disabled)
 
void setExpanded (bool expand)
 
void setFirstColumnSpanned (bool span)
 
void setFlags (Qt::ItemFlags flags)
 
void setFont (int column, const QFont &font)
 
void setForeground (int column, const QBrush &brush)
 
void setHidden (bool hide)
 
void setIcon (int column, const QIcon &icon)
 
void setSelected (bool select)
 
void setSizeHint (int column, const QSize &size)
 
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)
 
QSize sizeHint (int column) const
 
void sortChildren (int column, Qt::SortOrder order)
 
QString statusTip (int column) const
 
QTreeWidgetItem * takeChild (int index)
 
QList< QTreeWidgetItem * > takeChildren ()
 
QString text (int column) const
 
int textAlignment (int column) const
 
QColor textColor (int column) const
 
QString toolTip (int column) const
 
QTreeWidgettreeWidget () const
 
int type () const
 
QString whatsThis (int column) const
 
virtual void write (QDataStream &out) const
 

Protected Methods

void emitDataChanged ()
 

Friends

class QTreeWidget
 
class QTreeWidgetItemIterator
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &out, const QTreeWidgetItem &item)
 
QDataStreamoperator>> (QDataStream &in, QTreeWidgetItem &item)
 

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.

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 an entry for Oslo as a child item:

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

Member Enumeration Documentation

ConstantValueDescription
QTreeWidgetItem::ShowIndicator0The controls for expanding and collapsing will be shown for this item even if there are no children.
QTreeWidgetItem::DontShowIndicator1The 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::DontShowIndicatorWhenChildless2The controls for expanding and collapsing will be shown if the item contains children.

This enum describes the types that are used to describe tree widget items. You can define new user types in QTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

ConstantValueDescription
QTreeWidgetItem::Type0 The default type for tree widget items.
QTreeWidgetItem::UserType1000 The minimum value for custom types. Values below UserType are reserved for CopperSpice.
See also
type()

Constructor & Destructor Documentation

QTreeWidgetItem::QTreeWidgetItem ( int  type = Type)
explicit

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

See also
type()
QTreeWidgetItem::QTreeWidgetItem ( const QStringList strings,
int  type = Type 
)
explicit

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::QTreeWidgetItem ( QTreeWidget view,
int  type = Type 
)
explicit

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

See also
type()
QTreeWidgetItem::QTreeWidgetItem ( QTreeWidget view,
const QStringList strings,
int  type = 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::QTreeWidgetItem ( QTreeWidget view,
QTreeWidgetItem *  previous,
int  type = Type 
)

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

See also
type()
QTreeWidgetItem::QTreeWidgetItem ( QTreeWidgetItem *  parent,
int  type = Type 
)
explicit

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

See also
type()
QTreeWidgetItem::QTreeWidgetItem ( QTreeWidgetItem *  parent,
const QStringList strings,
int  type = Type 
)

Constructs a tree widget item and appends 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::QTreeWidgetItem ( QTreeWidgetItem *  parent,
QTreeWidgetItem *  previous,
int  type = Type 
)

Constructs a tree widget item of the specified type which is then inserted into the parent after the previous item.

See also
type()
QTreeWidgetItem::QTreeWidgetItem ( const QTreeWidgetItem &  other)

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

See also
data(), flags()
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.

Method Documentation

void QTreeWidgetItem::addChild ( QTreeWidgetItem *  child)

Appends the child item to the list of children.

See also
insertChild(), takeChild()
void QTreeWidgetItem::addChildren ( const QList< QTreeWidgetItem * > &  children)

Appends the given list of children to the item.

See also
insertChildren(), takeChildren()
QBrush QTreeWidgetItem::background ( int  column) const
inline

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

See also
setBackground(), foreground()
QColor QTreeWidgetItem::backgroundColor ( int  column) const
inlinedeprecated
Qt::CheckState QTreeWidgetItem::checkState ( int  column) const
inline

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

See also
setCheckState(), Qt::CheckState
QTreeWidgetItem * QTreeWidgetItem::child ( int  index) const
inline

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

See also
parent()
int QTreeWidgetItem::childCount ( ) const
inline

Returns the number of child items.

QTreeWidgetItem::ChildIndicatorPolicy QTreeWidgetItem::childIndicatorPolicy ( ) const

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

See also
setChildIndicatorPolicy()
QTreeWidgetItem * QTreeWidgetItem::clone ( ) const
virtual

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

int QTreeWidgetItem::columnCount ( ) const
inline

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.

See also
setData()
void QTreeWidgetItem::emitDataChanged ( )
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()
Qt::ItemFlags QTreeWidgetItem::flags ( ) 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()
QFont QTreeWidgetItem::font ( int  column) const
inline

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

See also
setFont()
QBrush QTreeWidgetItem::foreground ( int  column) const
inline

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

See also
setForeground(), background()
QIcon QTreeWidgetItem::icon ( int  column) const
inline

Returns the icon that is displayed in the specified column.

See also
setIcon(), QAbstractItemView::iconSize
int QTreeWidgetItem::indexOfChild ( QTreeWidgetItem *  child) const
inline

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. If the child has already been inserted somewhere else it will not be inserted again.

void QTreeWidgetItem::insertChildren ( 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 will not be inserted again.

bool QTreeWidgetItem::isDisabled ( ) const
inline

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

See also
setFlags()
bool QTreeWidgetItem::isExpanded ( ) const
inline

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

See also
setExpanded()
bool QTreeWidgetItem::isFirstColumnSpanned ( ) const
inline

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

See also
setFirstColumnSpanned()
bool QTreeWidgetItem::isHidden ( ) const
inline

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

See also
setHidden()
bool QTreeWidgetItem::isSelected ( ) const
inline

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

See also
setSelected()
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.

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

Copy assigns from other and returns a reference to this object. The values for type() and treeWidget() are not copied.

QTreeWidgetItem * QTreeWidgetItem::parent ( ) const
inline

Returns the item's parent.

See also
child()
void QTreeWidgetItem::read ( QDataStream in)
virtual

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

See also
write()
void QTreeWidgetItem::removeChild ( QTreeWidgetItem *  child)

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

void QTreeWidgetItem::setBackground ( int  column,
const QBrush brush 
)
inline

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

See also
background(), setForeground()
void QTreeWidgetItem::setBackgroundColor ( int  column,
const QColor color 
)
inlinedeprecated
void QTreeWidgetItem::setCheckState ( int  column,
Qt::CheckState  state 
)
inline

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

See also
checkState()
void QTreeWidgetItem::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()
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.

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

See also
data()
void QTreeWidgetItem::setDisabled ( bool  disabled)
inline

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

See also
isDisabled(), setFlags()
void QTreeWidgetItem::setExpanded ( bool  expand)
inline

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()
void QTreeWidgetItem::setFirstColumnSpanned ( bool  span)
inline

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

See also
isFirstColumnSpanned()
void QTreeWidgetItem::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()
void QTreeWidgetItem::setFont ( int  column,
const QFont font 
)
inline

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

See also
font(), setText(), setForeground()
void QTreeWidgetItem::setForeground ( int  column,
const QBrush brush 
)
inline

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

See also
foreground(), setBackground()
void QTreeWidgetItem::setHidden ( bool  hide)
inline

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

See also
isHidden()
void QTreeWidgetItem::setIcon ( int  column,
const QIcon icon 
)
inline

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

See also
icon(), setText(), QAbstractItemView::iconSize
void QTreeWidgetItem::setSelected ( bool  select)
inline

Sets the selected state of the item to select.

See also
isSelected()
void QTreeWidgetItem::setSizeHint ( int  column,
const QSize size 
)
inline

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()
void QTreeWidgetItem::setStatusTip ( int  column,
const QString statusTip 
)
inline

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()
void QTreeWidgetItem::setText ( int  column,
const QString text 
)
inline

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

See also
text(), setFont(), setForeground()
void QTreeWidgetItem::setTextAlignment ( int  column,
int  alignment 
)
inline

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

See also
textAlignment()
void QTreeWidgetItem::setTextColor ( int  column,
const QColor color 
)
inlinedeprecated
void QTreeWidgetItem::setToolTip ( int  column,
const QString toolTip 
)
inline

Sets the tooltip for the given column to toolTip.

See also
toolTip(), setStatusTip(), setWhatsThis()
void QTreeWidgetItem::setWhatsThis ( int  column,
const QString whatsThis 
)
inline

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

See also
whatsThis(), setStatusTip(), setToolTip()
QSize QTreeWidgetItem::sizeHint ( int  column) const
inline

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

See also
setSizeHint()
void QTreeWidgetItem::sortChildren ( int  column,
Qt::SortOrder  order 
)
inline

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.
QString QTreeWidgetItem::statusTip ( int  column) const
inline

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 a nullptr.

QList< QTreeWidgetItem * > QTreeWidgetItem::takeChildren ( )

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

QString QTreeWidgetItem::text ( int  column) const
inline

Returns the text in the specified column.

See also
setText()
int QTreeWidgetItem::textAlignment ( int  column) const
inline

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

See also
setTextAlignment()
QColor QTreeWidgetItem::textColor ( int  column) const
inlinedeprecated
QString QTreeWidgetItem::toolTip ( int  column) const
inline

Returns the tool tip for the given column.

See also
setToolTip()
QTreeWidget * QTreeWidgetItem::treeWidget ( ) const
inline

Returns the tree widget that contains the item.

int QTreeWidgetItem::type ( ) const
inline

Returns the type passed to the QTreeWidgetItem constructor.

QString QTreeWidgetItem::whatsThis ( int  column) const
inline

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

See also
setWhatsThis()
void QTreeWidgetItem::write ( QDataStream out) const
virtual

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

See also
read()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream out,
const QTreeWidgetItem &  item 
)
related

Writes the tree widget item to stream out and returns a reference to the stream. This operator uses QTreeWidgetItem::write().

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream in,
QTreeWidgetItem &  item 
)
related

Reads a tree widget item from stream in into item and returns a reference to the stream. This operator uses QTreeWidgetItem::read().

Refer to Serializing Data Types for additional information.