Qt 4.8
Public Types | Public Functions | Protected Functions | Private Functions | Properties | Friends | Related Functions | List of all members
QTreeWidgetItem Class Reference

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

#include <qtreewidget.h>

Public Types

enum  ChildIndicatorPolicy { ShowIndicator, DontShowIndicator, DontShowIndicatorWhenChildless }
 
enum  ItemType { Type = 0, UserType = 1000 }
 This enum describes the types that are used to describe tree widget items. More...
 

Public Functions

void addChild (QTreeWidgetItem *child)
 Appends the child item to the list of children. More...
 
void addChildren (const QList< QTreeWidgetItem *> &children)
 Appends the given list of children to the item. More...
 
QBrush background (int column) const
 Returns the brush used to render the background of the specified column. More...
 
QColor backgroundColor (int column) const
 This function is deprecated. More...
 
Qt::CheckState checkState (int column) const
 Returns the check state of the label in the given column. More...
 
QTreeWidgetItemchild (int index) const
 Returns the item at the given index in the list of the item's children. More...
 
int childCount () const
 Returns the number of child items. More...
 
QTreeWidgetItem::ChildIndicatorPolicy childIndicatorPolicy () const
 Returns the item indicator policy. More...
 
virtual QTreeWidgetItemclone () const
 Creates a deep copy of the item and of its children. More...
 
int columnCount () const
 Returns the number of columns in the item. More...
 
virtual QVariant data (int column, int role) const
 Returns the value for the item's column and role. More...
 
Qt::ItemFlags flags () const
 Returns the flags used to describe the item. More...
 
QFont font (int column) const
 Returns the font used to render the text in the specified column. More...
 
QBrush foreground (int column) const
 Returns the brush used to render the foreground (e. More...
 
QIcon icon (int column) const
 Returns the icon that is displayed in the specified column. More...
 
int indexOfChild (QTreeWidgetItem *child) const
 Returns the index of the given child in the item's list of children. More...
 
void insertChild (int index, QTreeWidgetItem *child)
 Inserts the child item at index in the list of children. More...
 
void insertChildren (int index, const QList< QTreeWidgetItem *> &children)
 Inserts the given list of children into the list of the item children at index . More...
 
bool isDisabled () const
 Returns true if the item is disabled; otherwise returns false. More...
 
bool isExpanded () const
 Returns true if the item is expanded, otherwise returns false. More...
 
bool isFirstColumnSpanned () const
 Returns true if the item is spanning all the columns in a row; otherwise returns false. More...
 
bool isHidden () const
 Returns true if the item is hidden, otherwise returns false. More...
 
bool isSelected () const
 Returns true if the item is selected, otherwise returns false. More...
 
virtual bool operator< (const QTreeWidgetItem &other) const
 Returns true if the text in the item is less than the text in the other item, otherwise returns false. More...
 
QTreeWidgetItemoperator= (const QTreeWidgetItem &other)
 Assigns other's data and flags to this item. More...
 
QTreeWidgetItemparent () const
 Returns the item's parent. More...
 
 QTreeWidgetItem (int type=Type)
 Constructs a tree widget item of the specified type. More...
 
 QTreeWidgetItem (const QStringList &strings, int type=Type)
 Constructs a tree widget item of the specified type. More...
 
 QTreeWidgetItem (QTreeWidget *view, int type=Type)
 Constructs a tree widget item of the specified type and appends it to the items in the given parent. More...
 
 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 parent. More...
 
 QTreeWidgetItem (QTreeWidget *view, QTreeWidgetItem *after, int type=Type)
 Constructs a tree widget item of the specified type and inserts it into the given parent after the preceding item. More...
 
 QTreeWidgetItem (QTreeWidgetItem *parent, int type=Type)
 Constructs a tree widget item and append it to the given parent. More...
 
 QTreeWidgetItem (QTreeWidgetItem *parent, const QStringList &strings, int type=Type)
 Constructs a tree widget item and append it to the given parent. More...
 
 QTreeWidgetItem (QTreeWidgetItem *parent, QTreeWidgetItem *after, int type=Type)
 Constructs a tree widget item of the specified type that is inserted into the parent after the preceding child item. More...
 
 QTreeWidgetItem (const QTreeWidgetItem &other)
 Constructs a copy of other. More...
 
virtual void read (QDataStream &in)
 Reads the item from stream in. More...
 
void removeChild (QTreeWidgetItem *child)
 Removes the given item indicated by child. More...
 
void setBackground (int column, const QBrush &brush)
 Sets the background brush of the label in the given column to the specified brush. More...
 
void setBackgroundColor (int column, const QColor &color)
 This function is deprecated. More...
 
void setCheckState (int column, Qt::CheckState state)
 Sets the item in the given column check state to be state. More...
 
void setChildIndicatorPolicy (QTreeWidgetItem::ChildIndicatorPolicy policy)
 Sets the item indicator policy. More...
 
virtual void setData (int column, int role, const QVariant &value)
 Sets the value for the item's column and role to the given value. More...
 
void setDisabled (bool disabled)
 Disables the item if disabled is true; otherwise enables the item. More...
 
void setExpanded (bool expand)
 Expands the item if expand is true, otherwise collapses the item. More...
 
void setFirstColumnSpanned (bool span)
 Sets the first section to span all columns if span is true; otherwise all item sections are shown. More...
 
void setFlags (Qt::ItemFlags flags)
 Sets the flags for the item to the given flags. More...
 
void setFont (int column, const QFont &font)
 Sets the font used to display the text in the given column to the given font. More...
 
void setForeground (int column, const QBrush &brush)
 Sets the foreground brush of the label in the given column to the specified brush. More...
 
void setHidden (bool hide)
 Hides the item if hide is true, otherwise shows the item. More...
 
void setIcon (int column, const QIcon &icon)
 Sets the icon to be displayed in the given column to icon. More...
 
void setSelected (bool select)
 Sets the selected state of the item to select. More...
 
void setSizeHint (int column, const QSize &size)
 Sets the size hint for the tree item in the given column to be size. More...
 
void setStatusTip (int column, const QString &statusTip)
 Sets the status tip for the given column to the given statusTip. More...
 
void setText (int column, const QString &text)
 Sets the text to be displayed in the given column to the given text. More...
 
void setTextAlignment (int column, int alignment)
 Sets the text alignment for the label in the given column to the alignment specified (see Qt::AlignmentFlag). More...
 
void setTextColor (int column, const QColor &color)
 This function is deprecated. More...
 
void setToolTip (int column, const QString &toolTip)
 Sets the tooltip for the given column to toolTip. More...
 
void setWhatsThis (int column, const QString &whatsThis)
 Sets the "What's This?" help for the given column to whatsThis. More...
 
QSize sizeHint (int column) const
 Returns the size hint set for the tree item in the given column (see QSize). More...
 
void sortChildren (int column, Qt::SortOrder order)
 Sorts the children of the item using the given order, by the values in the given column. More...
 
QString statusTip (int column) const
 Returns the status tip for the contents of the given column. More...
 
QTreeWidgetItemtakeChild (int index)
 Removes the item at index and returns it, otherwise return 0. More...
 
QList< QTreeWidgetItem * > takeChildren ()
 Removes the list of children and returns it, otherwise returns an empty list. More...
 
QString text (int column) const
 Returns the text in the specified column. More...
 
int textAlignment (int column) const
 Returns the text alignment for the label in the given column (see Qt::AlignmentFlag). More...
 
QColor textColor (int column) const
 This function is deprecated. More...
 
QString toolTip (int column) const
 Returns the tool tip for the given column. More...
 
QTreeWidgettreeWidget () const
 Returns the tree widget that contains the item. More...
 
int type () const
 Returns the type passed to the QTreeWidgetItem constructor. More...
 
QString whatsThis (int column) const
 Returns the "What's This?" help for the contents of the given column. More...
 
virtual void write (QDataStream &out) const
 Writes the item to stream out. More...
 
virtual ~QTreeWidgetItem ()
 Destroys this tree widget item. More...
 

Protected Functions

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

Private Functions

QVariant childrenCheckState (int column) const
 Calculates the checked state of the item based on the checked state of its children. More...
 
void executePendingSort () const
 
void itemChanged ()
 
void sortChildren (int column, Qt::SortOrder order, bool climb)
 Sorts the children by the value in the given column, in the order specified. More...
 

Properties

QList< QTreeWidgetItem * > children
 
QTreeWidgetItemPrivated
 
Qt::ItemFlags itemFlags
 
QTreeWidgetItempar
 
int rtti
 
QVector< QVector< QWidgetItemData > > values
 
QTreeWidgetview
 

Friends

class QTreeModel
 
class QTreeWidget
 
class QTreeWidgetItemIterator
 
class QTreeWidgetItemPrivate
 
class QTreeWidgetPrivate
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QTreeWidgetItem &item)
 Writes the tree widget item item to stream out. More...
 
QDataStreamoperator>> (QDataStream &in, QTreeWidgetItem &item)
 Reads a tree widget item from stream in into item. More...
 

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:

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, QTableWidgetItem

Definition at line 63 of file qtreewidget.h.

Enumerations

◆ ChildIndicatorPolicy

Since
4.3
  • ShowIndicator The controls for expanding and collapsing will be shown for this item even if there are no children.
  • DontShowIndicator 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.
  • DontShowIndicatorWhenChildless The controls for expanding and collapsing will be shown if the item contains children.
Enumerator
ShowIndicator 
DontShowIndicator 
DontShowIndicatorWhenChildless 

Definition at line 102 of file qtreewidget.h.

◆ ItemType

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

  • Type The default type for tree widget items.
  • UserType 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()
Enumerator
Type 
UserType 

Definition at line 71 of file qtreewidget.h.

Constructors and Destructors

◆ QTreeWidgetItem() [1/9]

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

Definition at line 1489 of file qtreewidget.cpp.

Referenced by clone().

1490  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1496 {
1497 }
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220

◆ QTreeWidgetItem() [2/9]

QTreeWidgetItem::QTreeWidgetItem ( 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()

Definition at line 1508 of file qtreewidget.cpp.

1509  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1515 {
1516  for (int i = 0; i < strings.count(); ++i)
1517  setText(i, strings.at(i));
1518 }
void setText(int column, const QString &text)
Sets the text to be displayed in the given column to the given text.
Definition: qtreewidget.h:226
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220

◆ QTreeWidgetItem() [3/9]

QTreeWidgetItem::QTreeWidgetItem ( QTreeWidget parent,
int  type = Type 
)
explicit

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

See also
type()

Definition at line 1529 of file qtreewidget.cpp.

1530  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1536 {
1537  if (view && view->model()) {
1538  QTreeModel *model = qobject_cast<QTreeModel*>(view->model());
1539  model->rootItem->addChild(this);
1540  values.reserve(model->headerItem->columnCount());
1541  }
1542 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * headerItem
void addChild(QTreeWidgetItem *child)
Appends the child item to the list of children.
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
QTreeWidgetItem * rootItem
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
QAbstractItemModel * model() const
Returns the model that this view is presenting.
int columnCount() const
Returns the number of columns in the item.
Definition: qtreewidget.h:191

◆ QTreeWidgetItem() [4/9]

QTreeWidgetItem::QTreeWidgetItem ( 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()

Definition at line 1554 of file qtreewidget.cpp.

1555  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1561 {
1562  for (int i = 0; i < strings.count(); ++i)
1563  setText(i, strings.at(i));
1564  if (view && view->model()) {
1565  QTreeModel *model = qobject_cast<QTreeModel*>(view->model());
1566  model->rootItem->addChild(this);
1567  values.reserve(model->headerItem->columnCount());
1568  }
1569 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
void setText(int column, const QString &text)
Sets the text to be displayed in the given column to the given text.
Definition: qtreewidget.h:226
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * headerItem
void addChild(QTreeWidgetItem *child)
Appends the child item to the list of children.
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QTreeWidgetItem * rootItem
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
QAbstractItemModel * model() const
Returns the model that this view is presenting.
int columnCount() const
Returns the number of columns in the item.
Definition: qtreewidget.h:191

◆ QTreeWidgetItem() [5/9]

QTreeWidgetItem::QTreeWidgetItem ( 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()

Definition at line 1579 of file qtreewidget.cpp.

1580  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1586 {
1587  if (view) {
1588  QTreeModel *model = qobject_cast<QTreeModel*>(view->model());
1589  if (model) {
1590  int i = model->rootItem->children.indexOf(after) + 1;
1591  model->rootItem->insertChild(i, this);
1592  values.reserve(model->headerItem->columnCount());
1593  }
1594  }
1595 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
void insertChild(int index, QTreeWidgetItem *child)
Inserts the child item at index in the list of children.
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * headerItem
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
QTreeWidgetItem * rootItem
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
QAbstractItemModel * model() const
Returns the model that this view is presenting.
int columnCount() const
Returns the number of columns in the item.
Definition: qtreewidget.h:191

◆ QTreeWidgetItem() [6/9]

QTreeWidgetItem::QTreeWidgetItem ( QTreeWidgetItem parent,
int  type = Type 
)
explicit

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

See also
type()

Definition at line 1602 of file qtreewidget.cpp.

1603  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1609 {
1610  if (parent)
1611  parent->addChild(this);
1612 }
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
QTreeWidget * view
Definition: qtreewidget.h:219
void addChild(QTreeWidgetItem *child)
Appends the child item to the list of children.
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220

◆ QTreeWidgetItem() [7/9]

QTreeWidgetItem::QTreeWidgetItem ( 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()

Definition at line 1620 of file qtreewidget.cpp.

1621  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1627 {
1628  for (int i = 0; i < strings.count(); ++i)
1629  setText(i, strings.at(i));
1630  if (parent)
1631  parent->addChild(this);
1632 }
void setText(int column, const QString &text)
Sets the text to be displayed in the given column to the given text.
Definition: qtreewidget.h:226
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
void addChild(QTreeWidgetItem *child)
Appends the child item to the list of children.
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220

◆ QTreeWidgetItem() [8/9]

QTreeWidgetItem::QTreeWidgetItem ( 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()

Definition at line 1642 of file qtreewidget.cpp.

1643  : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
1649 {
1650  if (parent) {
1651  int i = parent->children.indexOf(after) + 1;
1652  parent->insertChild(i, this);
1653  }
1654 }
void insertChild(int index, QTreeWidgetItem *child)
Inserts the child item at index in the list of children.
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * par
Definition: qtreewidget.h:221
int type() const
Returns the type passed to the QTreeWidgetItem constructor.
Definition: qtreewidget.h:203
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ QTreeWidgetItem() [9/9]

QTreeWidgetItem::QTreeWidgetItem ( const QTreeWidgetItem other)

Constructs a copy of other.

Since
4.1

Note that type() and treeWidget() are not copied.

This function is useful when reimplementing clone().

See also
data(), flags()

Definition at line 2045 of file qtreewidget.cpp.

2046  : rtti(Type), values(other.values), view(0),
2047  d(new QTreeWidgetItemPrivate(this)), par(0),
2048  itemFlags(other.itemFlags)
2049 {
2050  d->display = other.d->display;
2051 }
friend class QTreeWidgetItemPrivate
Definition: qtreewidget.h:69
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * par
Definition: qtreewidget.h:221
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218

◆ ~QTreeWidgetItem()

QTreeWidgetItem::~QTreeWidgetItem ( )
virtual

Destroys this tree widget item.

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

Definition at line 1664 of file qtreewidget.cpp.

1665 {
1666  QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
1667  bool wasSkipSort = false;
1668  if (model) {
1669  wasSkipSort = model->skipPendingSort;
1670  model->skipPendingSort = true;
1671  }
1672  if (par) {
1673  int i = par->children.indexOf(this);
1674  if (i >= 0) {
1675  if (model) model->beginRemoveItems(par, i, 1);
1676  // users _could_ do changes when connected to rowsAboutToBeRemoved,
1677  // so we check again to make sure 'i' is valid
1678  if (!par->children.isEmpty() && par->children.at(i) == this)
1679  par->children.takeAt(i);
1680  if (model) model->endRemoveItems();
1681  }
1682  } else if (model) {
1683  if (this == model->headerItem) {
1684  model->headerItem = 0;
1685  } else {
1686  int i = model->rootItem->children.indexOf(this);
1687  if (i >= 0) {
1688  model->beginRemoveItems(0, i, 1);
1689  // users _could_ do changes when connected to rowsAboutToBeRemoved,
1690  // so we check again to make sure 'i' is valid
1691  if (!model->rootItem->children.isEmpty() && model->rootItem->children.at(i) == this)
1692  model->rootItem->children.takeAt(i);
1693  model->endRemoveItems();
1694  }
1695  }
1696  }
1697  // at this point the persistent indexes for the children should also be invalidated
1698  // since we invalidated the parent
1699  for (int i = 0; i < children.count(); ++i) {
1701  // make sure the child does not try to remove itself from our children list
1702  child->par = 0;
1703  // make sure the child does not try to remove itself from the top level list
1704  child->view = 0;
1705  delete child;
1706  }
1707 
1708  children.clear();
1709  delete d;
1710  if (model) {
1711  model->skipPendingSort = wasSkipSort;
1712  }
1713 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * headerItem
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QTreeWidgetItem * par
Definition: qtreewidget.h:221
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QTreeWidgetItem * rootItem
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
void beginRemoveItems(QTreeWidgetItem *parent, int row, int count)
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void endRemoveItems()
bool skipPendingSort

Functions

◆ addChild()

void QTreeWidgetItem::addChild ( QTreeWidgetItem child)

Appends the child item to the list of children.

See also
insertChild() takeChild()

Definition at line 2075 of file qtreewidget.cpp.

Referenced by QTreeWidgetItem().

2076 {
2077  if (child) {
2079  child->d->rowGuess = children.count() - 1;
2080  }
2081 }
void insertChild(int index, QTreeWidgetItem *child)
Inserts the child item at index in the list of children.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ addChildren()

void QTreeWidgetItem::addChildren ( const QList< QTreeWidgetItem *> &  children)

Appends the given list of children to the item.

Since
4.1
See also
insertChildren() takeChildren()

Definition at line 2181 of file qtreewidget.cpp.

2182 {
2183  insertChildren(this->children.count(), children);
2184 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void insertChildren(int index, const QList< QTreeWidgetItem *> &children)
Inserts the given list of children into the list of the item children at index .
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ background()

QBrush QTreeWidgetItem::background ( int  column) const
inline

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

Since
4.2
See also
foreground()

Definition at line 147 of file qtreewidget.h.

148  { return qvariant_cast<QBrush>(data(column, Qt::BackgroundRole)); }
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ backgroundColor()

QColor QTreeWidgetItem::backgroundColor ( int  column) const
inline

This function is deprecated.

Use background() instead.

Definition at line 142 of file qtreewidget.h.

143  { return qvariant_cast<QColor>(data(column, Qt::BackgroundColorRole)); }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ checkState()

Qt::CheckState QTreeWidgetItem::checkState ( int  column) const
inline

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

See also
Qt::CheckState

Definition at line 162 of file qtreewidget.h.

Referenced by QTreeWidgetItemIterator::matchesFlags().

163  { return static_cast<Qt::CheckState>(data(column, Qt::CheckStateRole).toInt()); }
CheckState
Definition: qnamespace.h:1607
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ child()

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

Definition at line 184 of file qtreewidget.h.

Referenced by addChild(), QTreeModel::beginRemoveItems(), clone(), QTreeModel::index(), insertChildren(), QTreeWidgetItemIteratorPrivate::next(), QTreeWidgetItemIteratorPrivate::nextSibling(), QTreeWidgetItemIteratorPrivate::previous(), QTreeWidgetItemPrivate::propagateDisabled(), QTreeWidgetItemIterator::QTreeWidgetItemIterator(), setData(), setFlags(), and ~QTreeWidgetItem().

184  {
185  if (index < 0 || index >= children.size())
186  return 0;
188  return children.at(index);
189  }
void executePendingSort() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ childCount()

int QTreeWidgetItem::childCount ( ) const
inline

Returns the number of child items.

Definition at line 190 of file qtreewidget.h.

Referenced by QTreeModel::clear(), clone(), QTreeWidget::dropEvent(), QTreeModel::hasChildren(), insertChildren(), QTreeWidgetItemIterator::matchesFlags(), QTreeWidgetItemIteratorPrivate::next(), QTreeWidgetItemIteratorPrivate::previous(), and QTreeModel::rowCount().

190 { return children.count(); }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ childIndicatorPolicy()

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

Definition at line 1779 of file qtreewidget.cpp.

1780 {
1781  return d->policy;
1782 }
QTreeWidgetItem::ChildIndicatorPolicy policy
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220

◆ childrenCheckState()

QVariant QTreeWidgetItem::childrenCheckState ( int  column) const
private

Calculates the checked state of the item based on the checked state of its children.

Warning
This function is not part of the public interface.

E.g. if all children checked => this item is also checked; if some children checked => this item is partially checked; if no children checked => this item is unchecked.

Definition at line 2335 of file qtreewidget.cpp.

Referenced by data().

2336 {
2337  if (column < 0)
2338  return QVariant();
2339  bool checkedChildren = false;
2340  bool uncheckedChildren = false;
2341  for (int i = 0; i < children.count(); ++i) {
2342  QVariant value = children.at(i)->data(column, Qt::CheckStateRole);
2343  if (!value.isValid())
2344  return QVariant();
2345 
2346  switch (static_cast<Qt::CheckState>(value.toInt()))
2347  {
2348  case Qt::Unchecked:
2349  uncheckedChildren = true;
2350  break;
2351  case Qt::Checked:
2352  checkedChildren = true;
2353  break;
2354  case Qt::PartiallyChecked:
2355  default:
2356  return Qt::PartiallyChecked;
2357  }
2358  }
2359 
2360  if (uncheckedChildren && checkedChildren)
2361  return Qt::PartiallyChecked;
2362  if (uncheckedChildren)
2363  return Qt::Unchecked;
2364  else if (checkedChildren)
2365  return Qt::Checked;
2366  else
2367  return QVariant(); // value was not defined
2368 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ clone()

QTreeWidgetItem * QTreeWidgetItem::clone ( ) const
virtual

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

Definition at line 1718 of file qtreewidget.cpp.

1719 {
1720  QTreeWidgetItem *copy = 0;
1721 
1723  QStack<QTreeWidgetItem*> parentStack;
1724  stack.push(this);
1725  parentStack.push(0);
1726 
1727  QTreeWidgetItem *root = 0;
1728  const QTreeWidgetItem *item = 0;
1729  QTreeWidgetItem *parent = 0;
1730  while (!stack.isEmpty()) {
1731  // get current item, and copied parent
1732  item = stack.pop();
1733  parent = parentStack.pop();
1734 
1735  // copy item
1736  copy = new QTreeWidgetItem(*item);
1737  if (!root)
1738  root = copy;
1739 
1740  // set parent and add to parents children list
1741  if (parent) {
1742  copy->par = parent;
1743  parent->children.insert(0, copy);
1744  }
1745 
1746  for (int i = 0; i < item->childCount(); ++i) {
1747  stack.push(item->child(i));
1748  parentStack.push(copy);
1749  }
1750  }
1751  return root;
1752 }
int childCount() const
Returns the number of child items.
Definition: qtreewidget.h:190
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QTreeWidgetItem(int type=Type)
Constructs a tree widget item of the specified type.
QTreeWidgetItem * par
Definition: qtreewidget.h:221
QTreeWidgetItem * parent() const
Returns the item&#39;s parent.
Definition: qtreewidget.h:183
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ columnCount()

int QTreeWidgetItem::columnCount ( ) const
inline

Returns the number of columns in the item.

Definition at line 191 of file qtreewidget.h.

Referenced by QTreeModel::columnCount(), insertChild(), QTreeModel::itemChanged(), QTreeWidgetItem(), and QTreeWidget::setHeaderItem().

191 { return values.count(); }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218

◆ data()

QVariant QTreeWidgetItem::data ( int  column,
int  role 
) const
virtual

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

Definition at line 1956 of file qtreewidget.cpp.

Referenced by childrenCheckState(), QTreeModel::data(), QTreeModel::headerData(), QTreeModel::itemData(), operator<(), and setData().

1957 {
1958  switch (role) {
1959  case Qt::EditRole:
1960  case Qt::DisplayRole:
1961  if (column >= 0 && column < d->display.count())
1962  return d->display.at(column);
1963  break;
1964  case Qt::CheckStateRole:
1965  // special case for check state in tristate
1967  return childrenCheckState(column);
1968  // fallthrough intended
1969  default:
1970  if (column >= 0 && column < values.size()) {
1971  const QVector<QWidgetItemData> &column_values = values.at(column);
1972  for (int i = 0; i < column_values.count(); ++i)
1973  if (column_values.at(i).role == role)
1974  return column_values.at(i).value;
1975  }
1976  }
1977  return QVariant();
1978 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant childrenCheckState(int column) const
Calculates the checked state of the item based on the checked state of its children.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ emitDataChanged()

void QTreeWidgetItem::emitDataChanged ( )
protected

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

Since
4.5

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

See also
setData()

Definition at line 2385 of file qtreewidget.cpp.

2386 {
2387  itemChanged();
2388 }

◆ executePendingSort()

void QTreeWidgetItem::executePendingSort ( ) const
private
Warning
This function is not part of the public interface.

Definition at line 2402 of file qtreewidget.cpp.

2403 {
2404  if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0))
2405  model->executePendingSort();
2406 }
QTreeWidget * view
Definition: qtreewidget.h:219
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ flags()

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

Definition at line 1869 of file qtreewidget.cpp.

Referenced by QTreeWidgetItemIteratorPrivate::ensureValidIterator(), QTreeModel::flags(), isDisabled(), QTreeWidgetItemIterator::matchesFlags(), setDisabled(), and setFlags().

1870 {
1871  return itemFlags;
1872 }
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223

◆ font()

QFont QTreeWidgetItem::font ( int  column) const
inline

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

See also
setFont()

Definition at line 133 of file qtreewidget.h.

134  { return qvariant_cast<QFont>(data(column, Qt::FontRole)); }
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ foreground()

QBrush QTreeWidgetItem::foreground ( int  column) const
inline

Returns the brush used to render the foreground (e.

Since
4.2

g. text) of the specified column.

See also
background()

Definition at line 157 of file qtreewidget.h.

158  { return qvariant_cast<QBrush>(data(column, Qt::ForegroundRole)); }
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ icon()

QIcon QTreeWidgetItem::icon ( int  column) const
inline

Returns the icon that is displayed in the specified column.

See also
setIcon(), {QAbstractItemView::iconSize}{iconSize}

Definition at line 113 of file qtreewidget.h.

114  { return qvariant_cast<QIcon>(data(column, Qt::DecorationRole)); }
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ indexOfChild()

int QTreeWidgetItem::indexOfChild ( QTreeWidgetItem child) const
inline

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

Definition at line 250 of file qtreewidget.h.

Referenced by QTreeWidgetItemIteratorPrivate::ensureValidIterator(), and QTreeWidgetItemIteratorPrivate::nextSibling().

251 { executePendingSort(); return children.indexOf(achild); }
void executePendingSort() const
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ insertChild()

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 wont be inserted again.

Definition at line 2088 of file qtreewidget.cpp.

Referenced by addChild(), QTreeWidget::dropEvent(), insertChildren(), and QTreeWidgetItem().

2089 {
2090  if (index < 0 || index > children.count() || child == 0 || child->view != 0 || child->par != 0)
2091  return;
2092 
2093  if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0)) {
2094  const bool wasSkipSort = model->skipPendingSort;
2095  model->skipPendingSort = true;
2096  if (model->rootItem == this)
2097  child->par = 0;
2098  else
2099  child->par = this;
2100  if (view->isSortingEnabled()) {
2101  // do a delayed sort instead
2102  if (!model->sortPendingTimer.isActive())
2103  model->sortPendingTimer.start(0, model);
2104  }
2105  model->beginInsertItems(this, index, 1);
2106  int cols = model->columnCount();
2108  stack.push(child);
2109  while (!stack.isEmpty()) {
2110  QTreeWidgetItem *i = stack.pop();
2111  i->view = view;
2112  i->values.reserve(cols);
2113  for (int c = 0; c < i->children.count(); ++c)
2114  stack.push(i->children.at(c));
2115  }
2116  children.insert(index, child);
2117  model->endInsertItems();
2118  model->skipPendingSort = wasSkipSort;
2119  } else {
2120  child->par = this;
2121  children.insert(index, child);
2122  }
2123  if (child->par)
2124  d->propagateDisabled(child);
2125 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool isSortingEnabled() const
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QTreeWidgetItem * par
Definition: qtreewidget.h:221
void propagateDisabled(QTreeWidgetItem *item)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
QAbstractItemModel * model() const
Returns the model that this view is presenting.
int columnCount() const
Returns the number of columns in the item.
Definition: qtreewidget.h:191

◆ insertChildren()

void QTreeWidgetItem::insertChildren ( int  index,
const QList< QTreeWidgetItem *> &  children 
)

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

Since
4.1

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

Definition at line 2196 of file qtreewidget.cpp.

Referenced by addChildren().

2197 {
2198  if (view && view->isSortingEnabled()) {
2199  for (int n = 0; n < children.count(); ++n)
2200  insertChild(index, children.at(n));
2201  return;
2202  }
2203  QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
2205  QList<QTreeWidgetItem*> itemsToInsert;
2206  for (int n = 0; n < children.count(); ++n) {
2207  QTreeWidgetItem *child = children.at(n);
2208  if (child->view || child->par)
2209  continue;
2210  itemsToInsert.append(child);
2211  if (view && model) {
2212  if (child->childCount() == 0)
2213  child->view = view;
2214  else
2215  stack.push(child);
2216  }
2217  if (model && (model->rootItem == this))
2218  child->par = 0;
2219  else
2220  child->par = this;
2221  }
2222  if (!itemsToInsert.isEmpty()) {
2223  while (!stack.isEmpty()) {
2224  QTreeWidgetItem *i = stack.pop();
2225  i->view = view;
2226  for (int c = 0; c < i->children.count(); ++c)
2227  stack.push(i->children.at(c));
2228  }
2229  if (model) model->beginInsertItems(this, index, itemsToInsert.count());
2230  for (int n = 0; n < itemsToInsert.count(); ++n) {
2231  QTreeWidgetItem *child = itemsToInsert.at(n);
2232  this->children.insert(index + n, child);
2233  if (child->par)
2234  d->propagateDisabled(child);
2235  }
2236  if (model) model->endInsertItems();
2237  }
2238 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
unsigned char c[8]
Definition: qnumeric_p.h:62
bool isSortingEnabled() const
void insertChild(int index, QTreeWidgetItem *child)
Inserts the child item at index in the list of children.
int childCount() const
Returns the number of child items.
Definition: qtreewidget.h:190
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
void beginInsertItems(QTreeWidgetItem *parent, int row, int count)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QTreeWidgetItem * par
Definition: qtreewidget.h:221
void propagateDisabled(QTreeWidgetItem *item)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QTreeWidgetItem * rootItem
void endInsertItems()
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
QAbstractItemModel * model() const
Returns the model that this view is presenting.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ isDisabled()

bool QTreeWidgetItem::isDisabled ( ) const
inline

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

Since
4.3
See also
setFlags()

Definition at line 423 of file qtreewidget.h.

424 { return !(flags() & Qt::ItemIsEnabled); }
Qt::ItemFlags flags() const
Returns the flags used to describe the item.

◆ isExpanded()

bool QTreeWidgetItem::isExpanded ( ) const
inline

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

Since
4.2
See also
setExpanded()

Definition at line 411 of file qtreewidget.h.

412 { return (view ? view->isItemExpanded(this) : false); }
QTreeWidget * view
Definition: qtreewidget.h:219
bool isItemExpanded(const QTreeWidgetItem *item) const
Returns true if the given item is open; otherwise returns false.

◆ isFirstColumnSpanned()

bool QTreeWidgetItem::isFirstColumnSpanned ( ) const
inline

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

Since
4.3
See also
setFirstColumnSpanned()

Definition at line 417 of file qtreewidget.h.

418 { return (view ? view->isFirstItemColumnSpanned(this) : false); }
QTreeWidget * view
Definition: qtreewidget.h:219
bool isFirstItemColumnSpanned(const QTreeWidgetItem *item) const
Returns true if the given item is set to show only one section over all columns; otherwise returns fa...

◆ isHidden()

bool QTreeWidgetItem::isHidden ( ) const
inline

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

Since
4.2
See also
setHidden()

Definition at line 405 of file qtreewidget.h.

Referenced by QTreeWidgetItemIterator::matchesFlags().

406 { return (view ? view->isItemHidden(this) : false); }
QTreeWidget * view
Definition: qtreewidget.h:219
bool isItemHidden(const QTreeWidgetItem *item) const
Returns true if the item is explicitly hidden, otherwise returns false.

◆ isSelected()

bool QTreeWidgetItem::isSelected ( ) const
inline

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

Since
4.2
See also
setSelected()

Definition at line 399 of file qtreewidget.h.

Referenced by QTreeWidgetItemIterator::matchesFlags().

400 { return (view ? view->isItemSelected(this) : false); }
bool isItemSelected(const QTreeWidgetItem *item) const
Returns true if the item is selected; otherwise returns false.
QTreeWidget * view
Definition: qtreewidget.h:219

◆ itemChanged()

void QTreeWidgetItem::itemChanged ( )
private
Warning
This function is not part of the public interface.

Definition at line 2393 of file qtreewidget.cpp.

Referenced by emitDataChanged(), QTreeWidgetItemPrivate::propagateDisabled(), and setFlags().

2394 {
2395  if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0))
2396  model->itemChanged(this);
2397 }
QTreeWidget * view
Definition: qtreewidget.h:219
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ operator<()

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.

Definition at line 1985 of file qtreewidget.cpp.

1986 {
1987  int column = view ? view->sortColumn() : 0;
1988  const QVariant v1 = data(column, Qt::DisplayRole);
1989  const QVariant v2 = other.data(column, Qt::DisplayRole);
1991 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static bool variantLessThan(const QVariant &v1, const QVariant &v2)
This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort.
QTreeWidget * view
Definition: qtreewidget.h:219
int sortColumn() const
Returns the column used to sort the contents of the widget.
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ operator=()

QTreeWidgetItem & QTreeWidgetItem::operator= ( 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(), flags()

Definition at line 2061 of file qtreewidget.cpp.

2062 {
2063  values = other.values;
2064  d->display = other.d->display;
2065  d->policy = other.d->policy;
2066  itemFlags = other.itemFlags;
2067  return *this;
2068 }
QTreeWidgetItem::ChildIndicatorPolicy policy
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218

◆ parent()

QTreeWidgetItem * QTreeWidgetItem::parent ( ) const
inline

◆ read()

void QTreeWidgetItem::read ( QDataStream in)
virtual

Reads the item from stream in.

This only reads data into a single item.

See also
write()

Definition at line 2000 of file qtreewidget.cpp.

Referenced by operator>>().

2001 {
2002  // convert from streams written before we introduced display (4.2.0)
2003  if (in.version() < QDataStream::Qt_4_2) {
2004  d->display.clear();
2005  in >> values;
2006  // move the display value over to the display string list
2007  for (int column = 0; column < values.count(); ++column) {
2008  d->display << QVariant();
2009  for (int i = 0; i < values.at(column).count(); ++i) {
2010  if (values.at(column).at(i).role == Qt::DisplayRole) {
2011  d->display[column] = values.at(column).at(i).value;
2012  values[column].remove(i--);
2013  }
2014  }
2015  }
2016  } else {
2017  in >> values >> d->display;
2018  }
2019 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332

◆ removeChild()

void QTreeWidgetItem::removeChild ( QTreeWidgetItem child)

Removes the given item indicated by child.

The removed item will not be deleted.

Definition at line 2131 of file qtreewidget.cpp.

2132 {
2133  (void)takeChild(children.indexOf(child));
2134 }
QTreeWidgetItem * takeChild(int index)
Removes the item at index and returns it, otherwise return 0.
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ setBackground()

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

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

Since
4.2
See also
setForeground()

Definition at line 149 of file qtreewidget.h.

150  { setData(column, Qt::BackgroundRole, brush); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setBackgroundColor()

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

This function is deprecated.

Use setBackground() instead.

Definition at line 144 of file qtreewidget.h.

145  { setData(column, Qt::BackgroundColorRole, color); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setCheckState()

void QTreeWidgetItem::setCheckState ( int  column,
Qt::CheckState  state 
)
inline

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

See also
checkState()

Definition at line 164 of file qtreewidget.h.

165  { setData(column, Qt::CheckStateRole, state); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setChildIndicatorPolicy()

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

Definition at line 1761 of file qtreewidget.cpp.

1762 {
1763  if (d->policy == policy)
1764  return;
1765  d->policy = policy;
1766 
1767  if (!view)
1768  return;
1769 
1771 }
QTreeWidget * view
Definition: qtreewidget.h:219
void scheduleDelayedItemsLayout()
Schedules a layout of the items in the view to be executed when the event processing starts...
QTreeWidgetItem::ChildIndicatorPolicy policy
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220

◆ setData()

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.

Definition at line 1881 of file qtreewidget.cpp.

Referenced by QTreeModel::setData(), setData(), and QTreeModel::setHeaderData().

1882 {
1883  if (column < 0)
1884  return;
1885 
1886  QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
1887  switch (role) {
1888  case Qt::EditRole:
1889  case Qt::DisplayRole: {
1890  if (values.count() <= column) {
1891  if (model && this == model->headerItem)
1892  model->setColumnCount(column + 1);
1893  else
1894  values.resize(column + 1);
1895  }
1896  if (d->display.count() <= column) {
1897  for (int i = d->display.count() - 1; i < column - 1; ++i)
1898  d->display.append(QVariant());
1899  d->display.append(value);
1900  } else if (d->display[column] != value) {
1901  d->display[column] = value;
1902  } else {
1903  return; // value is unchanged
1904  }
1905  } break;
1906  case Qt::CheckStateRole:
1907  if (itemFlags & Qt::ItemIsTristate) {
1908  for (int i = 0; i < children.count(); ++i) {
1910  if (child->data(column, role).isValid()) {// has a CheckState
1911  Qt::ItemFlags f = itemFlags; // a little hack to avoid multiple dataChanged signals
1913  child->setData(column, role, value);
1914  itemFlags = f;
1915  }
1916  }
1917  }
1918  // Don't break, but fall through
1919  default:
1920  if (column < values.count()) {
1921  bool found = false;
1922  QVector<QWidgetItemData> column_values = values.at(column);
1923  for (int i = 0; i < column_values.count(); ++i) {
1924  if (column_values.at(i).role == role) {
1925  if (column_values.at(i).value == value)
1926  return; // value is unchanged
1927  values[column][i].value = value;
1928  found = true;
1929  break;
1930  }
1931  }
1932  if (!found)
1933  values[column].append(QWidgetItemData(role, value));
1934  } else {
1935  if (model && this == model->headerItem)
1936  model->setColumnCount(column + 1);
1937  else
1938  values.resize(column + 1);
1939  values[column].append(QWidgetItemData(role, value));
1940  }
1941  }
1942 
1943  if (model) {
1944  model->emitDataChanged(this, column);
1945  if (role == Qt::CheckStateRole) {
1946  QTreeWidgetItem *p;
1947  for (p = par; p && (p->itemFlags & Qt::ItemIsTristate); p = p->par)
1948  model->emitDataChanged(p, column);
1949  }
1950  }
1951 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
T qobject_cast(QObject *object)
Definition: qobject.h:375
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
QTreeWidgetItem * headerItem
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QTreeWidgetItem * par
Definition: qtreewidget.h:221
T value(int i) const
Returns the value at index position i in the vector.
Definition: qvector.h:559
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
Definition: qnamespace.h:54
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
void setColumnCount(int columns)
Sets the number of columns in the tree model.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void emitDataChanged(QTreeWidgetItem *item, int column)
Emits the dataChanged() signal for the given item.
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ setDisabled()

void QTreeWidgetItem::setDisabled ( bool  disabled)
inline

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

Since
4.3
See also
setFlags()

Definition at line 420 of file qtreewidget.h.

#define disabled
Qt::ItemFlags flags() const
Returns the flags used to describe the item.
void setFlags(Qt::ItemFlags flags)
Sets the flags for the item to the given flags.

◆ setExpanded()

void QTreeWidgetItem::setExpanded ( bool  expand)
inline

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

Since
4.2
Warning
The QTreeWidgetItem must be added to the QTreeWidget before calling this function.
See also
isExpanded()

Definition at line 408 of file qtreewidget.h.

409 { if (view) view->setItemExpanded(this, aexpand); }
QTreeWidget * view
Definition: qtreewidget.h:219
void setItemExpanded(const QTreeWidgetItem *item, bool expand)
Sets the item referred to by item to either closed or opened, depending on the value of expand...

◆ setFirstColumnSpanned()

void QTreeWidgetItem::setFirstColumnSpanned ( bool  span)
inline

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

Since
4.3
See also
isFirstColumnSpanned()

Definition at line 414 of file qtreewidget.h.

415 { if (view) view->setFirstItemColumnSpanned(this, aspan); }
QTreeWidget * view
Definition: qtreewidget.h:219
void setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span)
Sets the given item to only show one section for all columns if span is true; otherwise the item will...

◆ setFlags()

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

Definition at line 1795 of file qtreewidget.cpp.

Referenced by setDisabled().

1796 {
1797  const bool enable = (flags & Qt::ItemIsEnabled);
1798  const bool changedState = bool(itemFlags & Qt::ItemIsEnabled) != enable;
1799  const bool changedExplicit = d->disabled != !enable;
1800 
1801  d->disabled = !enable;
1802 
1803  if (enable && par && !(par->itemFlags & Qt::ItemIsEnabled)) // inherit from parent
1805  else // this item is explicitly disabled or has no parent
1806  itemFlags = flags;
1807 
1808  if (changedState && changedExplicit) { // if the propagate the change to the children
1809  QStack<QTreeWidgetItem*> parents;
1810  parents.push(this);
1811  while (!parents.isEmpty()) {
1812  QTreeWidgetItem *parent = parents.pop();
1813  for (int i = 0; i < parent->children.count(); ++i) {
1814  QTreeWidgetItem *child = parent->children.at(i);
1815  if (!child->d->disabled) { // if not explicitly disabled
1816  parents.push(child);
1817  if (enable)
1818  child->itemFlags = child->itemFlags | Qt::ItemIsEnabled;
1819  else
1820  child->itemFlags = child->itemFlags & ~Qt::ItemIsEnabled;
1821  child->itemChanged(); // ### we may want to optimize this
1822  }
1823  }
1824  }
1825  }
1826  itemChanged();
1827 }
Qt::ItemFlags flags() const
Returns the flags used to describe the item.
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QTreeWidgetItem * par
Definition: qtreewidget.h:221
QTreeWidgetItem * parent() const
Returns the item&#39;s parent.
Definition: qtreewidget.h:183
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
Qt::ItemFlags itemFlags
Definition: qtreewidget.h:223
QTreeWidgetItem * child(int index) const
Returns the item at the given index in the list of the item&#39;s children.
Definition: qtreewidget.h:184
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
Definition: qnamespace.h:54
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222

◆ setFont()

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

Definition at line 247 of file qtreewidget.h.

248 { setData(column, Qt::FontRole, afont); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

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

Since
4.2
See also
setBackground()

Definition at line 159 of file qtreewidget.h.

160  { setData(column, Qt::ForegroundRole, brush); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setHidden()

void QTreeWidgetItem::setHidden ( bool  hide)
inline

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

Since
4.2
See also
isHidden()

Definition at line 402 of file qtreewidget.h.

403 { if (view) view->setItemHidden(this, ahide); }
void setItemHidden(const QTreeWidgetItem *item, bool hide)
Hides the given item if hide is true; otherwise shows the item.
QTreeWidget * view
Definition: qtreewidget.h:219

◆ setIcon()

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}{iconSize}

Definition at line 229 of file qtreewidget.h.

230 { setData(column, Qt::DecorationRole, aicon); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setSelected()

void QTreeWidgetItem::setSelected ( bool  select)
inline

Sets the selected state of the item to select.

Since
4.2
See also
isSelected()

Definition at line 396 of file qtreewidget.h.

397 { if (view) view->setItemSelected(this, aselect); }
QTreeWidget * view
Definition: qtreewidget.h:219
void setItemSelected(const QTreeWidgetItem *item, bool select)
If select is true, the given item is selected; otherwise it is deselected.

◆ setSizeHint()

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

Sets the size hint for the tree item in the given column to be size.

Since
4.1

If no size hint is set, the item delegate will compute the size hint based on the item data.

Definition at line 169 of file qtreewidget.h.

170  { setData(column, Qt::SizeHintRole, size); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setStatusTip()

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

Definition at line 233 of file qtreewidget.h.

234 { setData(column, Qt::StatusTipRole, astatusTip); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setText()

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

Definition at line 226 of file qtreewidget.h.

Referenced by QTreeWidgetItem(), and QTreeWidget::setHeaderLabels().

227 { setData(column, Qt::DisplayRole, atext); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setTextAlignment()

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

Definition at line 139 of file qtreewidget.h.

140  { setData(column, Qt::TextAlignmentRole, alignment); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setTextColor()

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

This function is deprecated.

Use setForeground() instead.

Definition at line 154 of file qtreewidget.h.

155  { setData(column, Qt::TextColorRole, color); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ setToolTip()

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

Sets the tooltip for the given column to toolTip.

See also
toolTip() setStatusTip() setWhatsThis()

Definition at line 238 of file qtreewidget.h.

239 { setData(column, Qt::ToolTipRole, atoolTip); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

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

Definition at line 243 of file qtreewidget.h.

244 { setData(column, Qt::WhatsThisRole, awhatsThis); }
virtual void setData(int column, int role, const QVariant &value)
Sets the value for the item&#39;s column and role to the given value.

◆ sizeHint()

QSize QTreeWidgetItem::sizeHint ( int  column) const
inline

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

Since
4.1

Definition at line 167 of file qtreewidget.h.

168  { return qvariant_cast<QSize>(data(column, Qt::SizeHintRole)); }
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ sortChildren() [1/2]

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.

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

Definition at line 204 of file qtreewidget.h.

Referenced by QTreeModel::sort().

205  { sortChildren(column, order, false); }
void sortChildren(int column, Qt::SortOrder order)
Sorts the children of the item using the given order, by the values in the given column.
Definition: qtreewidget.h:204

◆ sortChildren() [2/2]

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

Sorts the children by the value in the given column, in the order specified.

Warning
This function is not part of the public interface.

If climb is true, the items below each of the children will also be sorted.

Definition at line 2308 of file qtreewidget.cpp.

2309 {
2310  QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
2311  if (!model)
2312  return;
2313  if (model->isChanging())
2314  return;
2315  QTreeModel::SkipSorting skipSorting(model);
2316  int oldSortColumn = view->d_func()->explicitSortColumn;
2317  view->d_func()->explicitSortColumn = column;
2318  emit model->layoutAboutToBeChanged();
2319  d->sortChildren(column, order, climb);
2320  emit model->layoutChanged();
2321  view->d_func()->explicitSortColumn = oldSortColumn;
2322 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
void sortChildren(int column, Qt::SortOrder order, bool climb)
QTreeWidget * view
Definition: qtreewidget.h:219
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
#define emit
Definition: qobjectdefs.h:76
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
bool isChanging() const
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ statusTip()

QString QTreeWidgetItem::statusTip ( int  column) const
inline

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

See also
setStatusTip()

Definition at line 117 of file qtreewidget.h.

118  { return data(column, Qt::StatusTipRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ takeChild()

QTreeWidgetItem * QTreeWidgetItem::takeChild ( int  index)

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

Definition at line 2139 of file qtreewidget.cpp.

Referenced by QTreeWidget::dropEvent(), and QTreeModel::removeRows().

2140 {
2141  // we move this outside the check of the index to allow executing
2142  // pending sorts from inline functions, using this function (hack)
2143  QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
2144  if (model) {
2145  // This will trigger a layoutChanged signal, thus we might want to optimize
2146  // this function by not emitting the rowsRemoved signal etc to the view.
2147  // On the other hand we also need to make sure that the selectionmodel
2148  // is updated in case we take an item that is selected.
2149  model->skipPendingSort = false;
2150  model->executePendingSort();
2151  }
2152  if (index >= 0 && index < children.count()) {
2153  if (model) model->beginRemoveItems(this, index, 1);
2155  item->par = 0;
2157  stack.push(item);
2158  while (!stack.isEmpty()) {
2159  QTreeWidgetItem *i = stack.pop();
2160  i->view = 0;
2161  for (int c = 0; c < i->children.count(); ++c)
2162  stack.push(i->children.at(c));
2163  }
2164  d->propagateDisabled(item);
2165  if (model) model->endRemoveRows();
2166  return item;
2167  }
2168  return 0;
2169 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
bool executePendingSort() const
unsigned char c[8]
Definition: qnumeric_p.h:62
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QTreeWidgetItem * par
Definition: qtreewidget.h:221
void propagateDisabled(QTreeWidgetItem *item)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void endRemoveRows()
Ends a row removal operation.
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
void beginRemoveItems(QTreeWidgetItem *parent, int row, int count)
quint16 index
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
QAbstractItemModel * model() const
Returns the model that this view is presenting.
bool skipPendingSort

◆ takeChildren()

QList< QTreeWidgetItem * > QTreeWidgetItem::takeChildren ( )

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

Since
4.1

Definition at line 2248 of file qtreewidget.cpp.

2249 {
2250  QList<QTreeWidgetItem*> removed;
2251  if (children.count() > 0) {
2252  QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
2253  if (model) {
2254  // This will trigger a layoutChanged signal, thus we might want to optimize
2255  // this function by not emitting the rowsRemoved signal etc to the view.
2256  // On the other hand we also need to make sure that the selectionmodel
2257  // is updated in case we take an item that is selected.
2258  model->executePendingSort();
2259  }
2260  if (model) model->beginRemoveItems(this, 0, children.count());
2261  for (int n = 0; n < children.count(); ++n) {
2262  QTreeWidgetItem *item = children.at(n);
2263  item->par = 0;
2265  stack.push(item);
2266  while (!stack.isEmpty()) {
2267  QTreeWidgetItem *i = stack.pop();
2268  i->view = 0;
2269  for (int c = 0; c < i->children.count(); ++c)
2270  stack.push(i->children.at(c));
2271  }
2272  d->propagateDisabled(item);
2273  }
2274  removed = children;
2275  children.clear(); // detach
2276  if (model) model->endRemoveItems();
2277  }
2278  return removed;
2279 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
bool executePendingSort() const
unsigned char c[8]
Definition: qnumeric_p.h:62
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QTreeWidget * view
Definition: qtreewidget.h:219
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
QTreeWidgetItem * par
Definition: qtreewidget.h:221
void propagateDisabled(QTreeWidgetItem *item)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class...
Definition: qtreewidget.h:63
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
void beginRemoveItems(QTreeWidgetItem *parent, int row, int count)
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QList< QTreeWidgetItem * > children
Definition: qtreewidget.h:222
QAbstractItemModel * model() const
Returns the model that this view is presenting.
void endRemoveItems()
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ text()

QString QTreeWidgetItem::text ( int  column) const
inline

Returns the text in the specified column.

See also
setText()

Definition at line 109 of file qtreewidget.h.

110  { return data(column, Qt::DisplayRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ textAlignment()

int QTreeWidgetItem::textAlignment ( int  column) const
inline

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

Definition at line 137 of file qtreewidget.h.

138  { return data(column, Qt::TextAlignmentRole).toInt(); }
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ textColor()

QColor QTreeWidgetItem::textColor ( int  column) const
inline

This function is deprecated.

Use foreground() instead.

Definition at line 152 of file qtreewidget.h.

153  { return qvariant_cast<QColor>(data(column, Qt::TextColorRole)); }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ toolTip()

QString QTreeWidgetItem::toolTip ( int  column) const
inline

Returns the tool tip for the given column.

See also
setToolTip()

Definition at line 122 of file qtreewidget.h.

123  { return data(column, Qt::ToolTipRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ treeWidget()

QTreeWidget * QTreeWidgetItem::treeWidget ( ) const
inline

Returns the tree widget that contains the item.

Definition at line 85 of file qtreewidget.h.

Referenced by QTreeWidgetItemIteratorPrivate::ensureValidIterator(), and QTreeWidgetItemIteratorPrivate::nextSibling().

85 { return view; }
QTreeWidget * view
Definition: qtreewidget.h:219

◆ type()

int QTreeWidgetItem::type ( ) const
inline

Returns the type passed to the QTreeWidgetItem constructor.

Definition at line 203 of file qtreewidget.h.

203 { return rtti; }

◆ whatsThis()

QString QTreeWidgetItem::whatsThis ( int  column) const
inline

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

See also
setWhatsThis()

Definition at line 128 of file qtreewidget.h.

129  { return data(column, Qt::WhatsThisRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int column, int role) const
Returns the value for the item&#39;s column and role.

◆ write()

void QTreeWidgetItem::write ( QDataStream out) const
virtual

Writes the item to stream out.

This only writes data from one single item.

See also
read()

Definition at line 2026 of file qtreewidget.cpp.

Referenced by operator<<().

2027 {
2028  out << values << d->display;
2029 }
QTreeWidgetItemPrivate * d
Definition: qtreewidget.h:220
QVector< QVector< QWidgetItemData > > values
Definition: qtreewidget.h:218

Friends and Related Functions

◆ operator<<()

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

Writes the tree widget item item to stream out.

This operator uses QTreeWidgetItem::write().

See also
{Serializing Qt Data Types}

Definition at line 2422 of file qtreewidget.cpp.

2423 {
2424  item.write(out);
2425  return out;
2426 }
virtual void write(QDataStream &out) const
Writes the item to stream out.

◆ operator>>()

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

Reads a tree widget item from stream in into item.

This operator uses QTreeWidgetItem::read().

See also
{Serializing Qt Data Types}

Definition at line 2440 of file qtreewidget.cpp.

2441 {
2442  item.read(in);
2443  return in;
2444 }
virtual void read(QDataStream &in)
Reads the item from stream in.

◆ QTreeModel

friend class QTreeModel
friend

Definition at line 65 of file qtreewidget.h.

◆ QTreeWidget

friend class QTreeWidget
friend

Definition at line 66 of file qtreewidget.h.

◆ QTreeWidgetItemIterator

Definition at line 68 of file qtreewidget.h.

◆ QTreeWidgetItemPrivate

Definition at line 69 of file qtreewidget.h.

◆ QTreeWidgetPrivate

friend class QTreeWidgetPrivate
friend

Definition at line 67 of file qtreewidget.h.

Properties

◆ children

QList<QTreeWidgetItem*> QTreeWidgetItem::children
private

◆ d

QTreeWidgetItemPrivate* QTreeWidgetItem::d
private

◆ itemFlags

Qt::ItemFlags QTreeWidgetItem::itemFlags
private

◆ par

QTreeWidgetItem* QTreeWidgetItem::par
private

◆ rtti

int QTreeWidgetItem::rtti
private

Definition at line 216 of file qtreewidget.h.

◆ values

QVector< QVector<QWidgetItemData> > QTreeWidgetItem::values
private

◆ view

QTreeWidget* QTreeWidgetItem::view
private

The documentation for this class was generated from the following files: