![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class. More...
#include <qtreewidget.h>
Public Types | |
enum | ItemType { Type = 0 , UserType = 1000 } |
This enum describes the types that are used to describe tree widget items. More... | |
enum | ChildIndicatorPolicy { ShowIndicator , DontShowIndicator , DontShowIndicatorWhenChildless } |
\value ShowIndicator The controls for expanding and collapsing will be shown for this item even if there are no children. More... |
Public Member Functions | |
QTreeWidgetItem (int type=Type) | |
Constructs a tree widget item of the specified type. | |
QTreeWidgetItem (const QStringList &strings, int type=Type) | |
Constructs a tree widget item of the specified type. | |
QTreeWidgetItem (QTreeWidget *treeview, int type=Type) | |
Constructs a tree widget item of the specified type and appends it to the items in the given parent. | |
QTreeWidgetItem (QTreeWidget *treeview, 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. | |
QTreeWidgetItem (QTreeWidget *treeview, 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. | |
QTreeWidgetItem (QTreeWidgetItem *parent, int type=Type) | |
Constructs a tree widget item and append it to the given parent. | |
QTreeWidgetItem (QTreeWidgetItem *parent, const QStringList &strings, int type=Type) | |
Constructs a tree widget item and append it to the given parent. | |
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. | |
QTreeWidgetItem (const QTreeWidgetItem &other) | |
Constructs a copy of other. | |
virtual | ~QTreeWidgetItem () |
Destroys this tree widget item. | |
virtual QTreeWidgetItem * | clone () const |
Creates a deep copy of the item and of its children. | |
QTreeWidget * | treeWidget () const |
Returns the tree widget that contains the item. | |
void | setSelected (bool select) |
Sets the selected state of the item to select. | |
bool | isSelected () const |
Returns true if the item is selected, otherwise returns false . | |
void | setHidden (bool hide) |
Hides the item if hide is true, otherwise shows the item. | |
bool | isHidden () const |
Returns true if the item is hidden, otherwise returns false . | |
void | setExpanded (bool expand) |
Expands the item if expand is true, otherwise collapses the item. | |
bool | isExpanded () const |
Returns true if the item is expanded, otherwise returns false . | |
void | setFirstColumnSpanned (bool span) |
Sets the first section to span all columns if span is true; otherwise all item sections are shown. | |
bool | isFirstColumnSpanned () const |
Returns true if the item is spanning all the columns in a row; otherwise returns false . | |
void | setDisabled (bool disabled) |
Disables the item if disabled is true; otherwise enables the item. | |
bool | isDisabled () const |
Returns true if the item is disabled; otherwise returns false . | |
void | setChildIndicatorPolicy (QTreeWidgetItem::ChildIndicatorPolicy policy) |
Sets the item indicator policy. | |
QTreeWidgetItem::ChildIndicatorPolicy | childIndicatorPolicy () const |
Returns the item indicator policy. | |
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. | |
QString | text (int column) const |
Returns the text in the specified column. | |
void | setText (int column, const QString &text) |
Sets the text to be displayed in the given column to the given text. | |
QIcon | icon (int column) const |
Returns the icon that is displayed in the specified column. | |
void | setIcon (int column, const QIcon &icon) |
Sets the icon to be displayed in the given column to icon. | |
QString | statusTip (int column) const |
Returns the status tip for the contents of the given column. | |
void | setStatusTip (int column, const QString &statusTip) |
Sets the status tip for the given column to the given statusTip. | |
QFont | font (int column) const |
Returns the font used to render the text in the specified column. | |
void | setFont (int column, const QFont &font) |
Sets the font used to display the text in the given column to the given font. | |
Qt::Alignment | textAlignment (int column) const |
void | setTextAlignment (int column, Qt::Alignment alignment) |
\obsolete [6.4] Use the overload that takes a Qt::Alignment argument. | |
QBrush | background (int column) const |
Returns the brush used to render the background of the specified column. | |
void | setBackground (int column, const QBrush &brush) |
Sets the background brush of the label in the given column to the specified brush. | |
QBrush | foreground (int column) const |
Returns the brush used to render the foreground (e.g. | |
void | setForeground (int column, const QBrush &brush) |
Sets the foreground brush of the label in the given column to the specified brush. | |
Qt::CheckState | checkState (int column) const |
Returns the check state of the label in the given column. | |
void | setCheckState (int column, Qt::CheckState state) |
Sets the item in the given column check state to be state. | |
QSize | sizeHint (int column) const |
Returns the size hint set for the tree item in the given column (see \l{QSize}). | |
void | setSizeHint (int column, const QSize &size) |
Sets the size hint for the tree item in the given column to be size. | |
virtual QVariant | data (int column, int role) const |
Returns the value for the item's column and role. | |
virtual void | setData (int column, int role, const QVariant &value) |
Sets the value for the item's column and role to the given value. | |
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 . | |
virtual void | read (QDataStream &in) |
Reads the item from stream in. | |
virtual void | write (QDataStream &out) const |
Writes the item to stream out. | |
QTreeWidgetItem & | operator= (const QTreeWidgetItem &other) |
Assigns other's data and flags to this item. | |
QTreeWidgetItem * | parent () const |
Returns the item's parent. | |
QTreeWidgetItem * | child (int index) const |
Returns the item at the given index in the list of the item's children. | |
int | childCount () const |
Returns the number of child items. | |
int | columnCount () const |
Returns the number of columns in the item. | |
int | indexOfChild (QTreeWidgetItem *child) const |
Returns the index of the given child in the item's list of children. | |
void | addChild (QTreeWidgetItem *child) |
Appends the child item to the list of children. | |
void | insertChild (int index, QTreeWidgetItem *child) |
Inserts the child item at index in the list of children. | |
void | removeChild (QTreeWidgetItem *child) |
Removes the given item indicated by child. | |
QTreeWidgetItem * | takeChild (int index) |
Removes the item at index and returns it, otherwise return 0. | |
void | addChildren (const QList< QTreeWidgetItem * > &children) |
Appends the given list of children to the item. | |
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 * > | takeChildren () |
Removes the list of children and returns it, otherwise returns an empty list. | |
int | type () const |
Returns the type passed to the QTreeWidgetItem constructor. | |
void | sortChildren (int column, Qt::SortOrder order) |
Sorts the children of the item using the given order, by the values in the given column. |
Protected Member Functions | |
void | emitDataChanged () |
Causes the model associated with this item to emit a \l{QAbstractItemModel::dataChanged()}{dataChanged}() signal for this item. |
Friends | |
class | QTreeModel |
class | QTreeWidget |
class | QTreeWidgetPrivate |
class | QTreeWidgetItemIterator |
class | QTreeWidgetItemPrivate |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &out, const QTreeWidgetItem &item) |
Writes the tree widget item item to stream out. | |
QDataStream & | operator>> (QDataStream &in, QTreeWidgetItem &item) |
Reads a tree widget item from stream in into item. |
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class.
\inmodule QtWidgets
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:
Items can be added in a particular order by specifying the item they follow when they are constructed:
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 \l{Qt::ItemFlags}). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.
Definition at line 23 of file qtreewidget.h.
\value ShowIndicator The controls for expanding and collapsing will be shown for this item even if there are no children.
\value 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. \value DontShowIndicatorWhenChildless The controls for expanding and collapsing will be shown if the item contains children.
Enumerator | |
---|---|
ShowIndicator | |
DontShowIndicator | |
DontShowIndicatorWhenChildless |
Definition at line 62 of file qtreewidget.h.
This enum describes the types that are used to describe tree widget items.
\value Type The default type for tree widget items. \value 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.
Enumerator | |
---|---|
Type | |
UserType |
Definition at line 31 of file qtreewidget.h.
|
explicit |
Constructs a tree widget item of the specified type.
The item must be inserted into a tree widget.
Definition at line 1379 of file qtreewidget.cpp.
|
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.
Definition at line 1389 of file qtreewidget.cpp.
|
explicit |
Constructs a tree widget item of the specified type and appends it to the items in the given parent.
Definition at line 1405 of file qtreewidget.cpp.
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.
Definition at line 1425 of file qtreewidget.cpp.
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.
Definition at line 1445 of file qtreewidget.cpp.
|
explicit |
Constructs a tree widget item and append it to the given parent.
Definition at line 1461 of file qtreewidget.cpp.
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.
Definition at line 1474 of file qtreewidget.cpp.
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.
Definition at line 1491 of file qtreewidget.cpp.
QTreeWidgetItem::QTreeWidgetItem | ( | const QTreeWidgetItem & | other | ) |
Constructs a copy of other.
Note that type() and treeWidget() are not copied.
This function is useful when reimplementing clone().
Definition at line 1899 of file qtreewidget.cpp.
|
virtual |
Destroys this tree widget item.
The item will be removed from \l{QTreeWidget}s to which it has been added. This makes it safe to delete an item at any time.
Definition at line 1508 of file qtreewidget.cpp.
void QTreeWidgetItem::addChild | ( | QTreeWidgetItem * | child | ) |
Appends the child item to the list of children.
Definition at line 1930 of file qtreewidget.cpp.
void QTreeWidgetItem::addChildren | ( | const QList< QTreeWidgetItem * > & | children | ) |
Appends the given list of children to the item.
Definition at line 2031 of file qtreewidget.cpp.
|
inline |
Returns the brush used to render the background of the specified column.
Definition at line 114 of file qtreewidget.h.
|
inline |
Returns the check state of the label in the given column.
Definition at line 124 of file qtreewidget.h.
|
inline |
Returns the item at the given index in the list of the item's children.
Definition at line 146 of file qtreewidget.h.
|
inline |
Returns the number of child items.
Definition at line 152 of file qtreewidget.h.
QTreeWidgetItem::ChildIndicatorPolicy QTreeWidgetItem::childIndicatorPolicy | ( | ) | const |
Returns the item indicator policy.
This policy decides when the tree branch expand/collapse indicator is shown.
Definition at line 1617 of file qtreewidget.cpp.
|
virtual |
Creates a deep copy of the item and of its children.
Definition at line 1556 of file qtreewidget.cpp.
|
inline |
Returns the number of columns in the item.
Definition at line 153 of file qtreewidget.h.
|
virtual |
Returns the value for the item's column and role.
Definition at line 1814 of file qtreewidget.cpp.
|
protected |
Causes the model associated with this item to emit a \l{QAbstractItemModel::dataChanged()}{dataChanged}() signal for this item.
You normally only need to call this function if you have subclassed QTreeWidgetItem and reimplemented data() and/or setData().
Definition at line 2219 of file qtreewidget.cpp.
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 | Qt::ItemIsDropEnabled.
Definition at line 1721 of file qtreewidget.cpp.
|
inline |
Returns the font used to render the text in the specified column.
Definition at line 93 of file qtreewidget.h.
|
inline |
Returns the brush used to render the foreground (e.g.
text) of the specified column. Setting a default-constructed brush will let the view use the default color from the style.
Definition at line 119 of file qtreewidget.h.
|
inline |
Returns the icon that is displayed in the specified column.
Definition at line 73 of file qtreewidget.h.
|
inline |
Returns the index of the given child in the item's list of children.
Definition at line 216 of file qtreewidget.h.
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 won't be inserted again.
Definition at line 1943 of file qtreewidget.cpp.
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 won't be inserted.
Definition at line 2041 of file qtreewidget.cpp.
|
inline |
Returns true
if the item is disabled; otherwise returns false
.
Definition at line 349 of file qtreewidget.h.
bool QTreeWidgetItem::isExpanded | ( | ) | const |
Returns true
if the item is expanded, otherwise returns false
.
Definition at line 1079 of file qtreewidget.cpp.
bool QTreeWidgetItem::isFirstColumnSpanned | ( | ) | const |
Returns true
if the item is spanning all the columns in a row; otherwise returns false
.
Definition at line 1112 of file qtreewidget.cpp.
bool QTreeWidgetItem::isHidden | ( | ) | const |
Returns true
if the item is hidden, otherwise returns false
.
Definition at line 1042 of file qtreewidget.cpp.
bool QTreeWidgetItem::isSelected | ( | ) | const |
Returns true
if the item is selected, otherwise returns false
.
Definition at line 1004 of file qtreewidget.cpp.
|
virtual |
Returns true
if the text in the item is less than the text in the other item, otherwise returns false
.
Definition at line 1844 of file qtreewidget.cpp.
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().
Definition at line 1916 of file qtreewidget.cpp.
|
inline |
|
virtual |
Reads the item from stream in.
This only reads data into a single item.
Definition at line 1859 of file qtreewidget.cpp.
void QTreeWidgetItem::removeChild | ( | QTreeWidgetItem * | child | ) |
Removes the given item indicated by child.
The removed item will not be deleted.
Definition at line 1985 of file qtreewidget.cpp.
Sets the background brush of the label in the given column to the specified brush.
Setting a default-constructed brush will let the view use the default color from the style.
Definition at line 116 of file qtreewidget.h.
|
inline |
Sets the item in the given column check state to be state.
Definition at line 126 of file qtreewidget.h.
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 DontShowIndicatorWhenChildless.
Definition at line 1599 of file qtreewidget.cpp.
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 1736 of file qtreewidget.cpp.
|
inline |
Disables the item if disabled is true; otherwise enables the item.
Definition at line 346 of file qtreewidget.h.
void QTreeWidgetItem::setExpanded | ( | bool | expand | ) |
Expands the item if expand is true, otherwise collapses the item.
Definition at line 1063 of file qtreewidget.cpp.
void QTreeWidgetItem::setFirstColumnSpanned | ( | bool | span | ) |
Sets the first section to span all columns if span is true; otherwise all item sections are shown.
Definition at line 1096 of file qtreewidget.cpp.
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.
Definition at line 1630 of file qtreewidget.cpp.
Sets the font used to display the text in the given column to the given font.
Definition at line 213 of file qtreewidget.h.
Sets the foreground brush of the label in the given column to the specified brush.
Definition at line 121 of file qtreewidget.h.
void QTreeWidgetItem::setHidden | ( | bool | hide | ) |
Hides the item if hide is true, otherwise shows the item.
setHidden(true)
on an item and only then adding it to a view will result in a visible item.Definition at line 1020 of file qtreewidget.cpp.
Sets the icon to be displayed in the given column to icon.
Definition at line 195 of file qtreewidget.h.
void QTreeWidgetItem::setSelected | ( | bool | select | ) |
Sets the selected state of the item to select.
Definition at line 985 of file qtreewidget.cpp.
Sets the size hint for the tree item in the given column to be size.
If no size hint is set or size is invalid, the item delegate will compute the size hint based on the item data.
Definition at line 131 of file qtreewidget.h.
Sets the status tip for the given column to the given statusTip.
QTreeWidget mouse tracking needs to be enabled for this feature to work.
Sets the text to be displayed in the given column to the given text.
Definition at line 192 of file qtreewidget.h.
|
inline |
\obsolete [6.4] Use the overload that takes a Qt::Alignment argument.
Sets the text alignment for the label in the given column to the alignment specified.
Sets the text alignment for the label in the given column to the alignment specified.
Definition at line 111 of file qtreewidget.h.
|
inline |
Returns the size hint set for the tree item in the given column (see \l{QSize}).
Definition at line 129 of file qtreewidget.h.
|
inline |
Sorts the children of the item using the given order, by the values in the given column.
Definition at line 166 of file qtreewidget.h.
|
inline |
Returns the status tip for the contents of the given column.
Definition at line 77 of file qtreewidget.h.
QTreeWidgetItem * QTreeWidgetItem::takeChild | ( | int | index | ) |
Removes the item at index and returns it, otherwise return 0.
Definition at line 1993 of file qtreewidget.cpp.
QList< QTreeWidgetItem * > QTreeWidgetItem::takeChildren | ( | ) |
Removes the list of children and returns it, otherwise returns an empty list.
Definition at line 2092 of file qtreewidget.cpp.
|
inline |
Returns the text in the specified column.
Definition at line 69 of file qtreewidget.h.
|
inline |
Returns the text alignment for the label in the given column.
Definition at line 101 of file qtreewidget.h.
|
inline |
Returns the tree widget that contains the item.
Definition at line 45 of file qtreewidget.h.
|
inline |
Returns the type passed to the QTreeWidgetItem constructor.
Definition at line 165 of file qtreewidget.h.
|
virtual |
Writes the item to stream out.
This only writes data from one single item.
Definition at line 1885 of file qtreewidget.cpp.
|
Writes the tree widget item item to stream out.
This operator uses QTreeWidgetItem::write().
Definition at line 2264 of file qtreewidget.cpp.
|
Reads a tree widget item from stream in into item.
This operator uses QTreeWidgetItem::read().
Definition at line 2279 of file qtreewidget.cpp.
|
friend |
Definition at line 25 of file qtreewidget.h.
|
friend |
Definition at line 26 of file qtreewidget.h.
|
friend |
Definition at line 28 of file qtreewidget.h.
|
friend |
Definition at line 29 of file qtreewidget.h.
|
friend |
Definition at line 27 of file qtreewidget.h.