QTreeWidgetItem Class
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class. More...
Header: | #include <QTreeWidgetItem> |
qmake: | QT += widgets |
Public Types
enum | ChildIndicatorPolicy { ShowIndicator, DontShowIndicator, DontShowIndicatorWhenChildless } |
enum | ItemType { Type, UserType } |
Public Functions
QTreeWidgetItem(int type = Type) | |
QTreeWidgetItem(const QStringList &strings, int type = Type) | |
QTreeWidgetItem(QTreeWidget *view, int type = Type) | |
QTreeWidgetItem(QTreeWidget *view, const QStringList &strings, int type = Type) | |
QTreeWidgetItem(QTreeWidget *view, QTreeWidgetItem *after, int type = Type) | |
QTreeWidgetItem(QTreeWidgetItem *parent, int type = Type) | |
QTreeWidgetItem(QTreeWidgetItem *parent, const QStringList &strings, int type = Type) | |
QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, int type = Type) | |
QTreeWidgetItem(const QTreeWidgetItem &other) | |
virtual | ~QTreeWidgetItem() |
void | addChild(QTreeWidgetItem *child) |
void | addChildren(const QList<QTreeWidgetItem *> &children) |
QBrush | background(int column) const |
QColor | backgroundColor(int column) const |
Qt::CheckState | checkState(int column) const |
QTreeWidgetItem * | child(int index) const |
int | childCount() const |
QTreeWidgetItem::ChildIndicatorPolicy | childIndicatorPolicy() const |
virtual QTreeWidgetItem * | clone() const |
int | columnCount() const |
virtual QVariant | data(int column, int role) const |
Qt::ItemFlags | flags() const |
QFont | font(int column) const |
QBrush | foreground(int column) const |
QIcon | icon(int column) const |
int | indexOfChild(QTreeWidgetItem *child) const |
void | insertChild(int index, QTreeWidgetItem *child) |
void | insertChildren(int index, const QList<QTreeWidgetItem *> &children) |
bool | isDisabled() const |
bool | isExpanded() const |
bool | isFirstColumnSpanned() const |
bool | isHidden() const |
bool | isSelected() const |
QTreeWidgetItem * | parent() const |
virtual void | read(QDataStream &in) |
void | removeChild(QTreeWidgetItem *child) |
void | setBackground(int column, const QBrush &brush) |
void | setBackgroundColor(int column, const QColor &color) |
void | setCheckState(int column, Qt::CheckState state) |
void | setChildIndicatorPolicy(QTreeWidgetItem::ChildIndicatorPolicy policy) |
virtual void | setData(int column, int role, const QVariant &value) |
void | setDisabled(bool disabled) |
void | setExpanded(bool expand) |
void | setFirstColumnSpanned(bool span) |
void | setFlags(Qt::ItemFlags flags) |
void | setFont(int column, const QFont &font) |
void | setForeground(int column, const QBrush &brush) |
void | setHidden(bool hide) |
void | setIcon(int column, const QIcon &icon) |
void | setSelected(bool select) |
void | setSizeHint(int column, const QSize &size) |
void | setStatusTip(int column, const QString &statusTip) |
void | setText(int column, const QString &text) |
void | setTextAlignment(int column, int alignment) |
void | setTextColor(int column, const QColor &color) |
void | setToolTip(int column, const QString &toolTip) |
void | setWhatsThis(int column, const QString &whatsThis) |
QSize | sizeHint(int column) const |
void | sortChildren(int column, Qt::SortOrder order) |
QString | statusTip(int column) const |
QTreeWidgetItem * | takeChild(int index) |
QList<QTreeWidgetItem *> | takeChildren() |
QString | text(int column) const |
int | textAlignment(int column) const |
QColor | textColor(int column) const |
QString | toolTip(int column) const |
QTreeWidget * | treeWidget() const |
int | type() const |
QString | whatsThis(int column) const |
virtual void | write(QDataStream &out) const |
virtual bool | operator<(const QTreeWidgetItem &other) const |
QTreeWidgetItem & | operator=(const QTreeWidgetItem &other) |
Protected Functions
void | emitDataChanged() |
Related Non-Members
QDataStream & | operator<<(QDataStream &out, const QTreeWidgetItem &item) |
QDataStream & | operator>>(QDataStream &in, QTreeWidgetItem &item) |
Detailed Description
The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class.
Tree widget items are used to hold rows of information for tree widgets. Rows usually contain several columns of data, each of which can contain a text label and an icon.
The QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with the QTreeWidget class.
Items are usually constructed with a parent that is either a QTreeWidget (for top-level items) or a QTreeWidgetItem (for items on lower levels of the tree). For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:
QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget); cities->setText(0, tr("Cities")); QTreeWidgetItem *osloItem = new QTreeWidgetItem(cities); osloItem->setText(0, tr("Oslo")); osloItem->setText(1, tr("Yes"));
Items can be added in a particular order by specifying the item they follow when they are constructed:
QTreeWidgetItem *planets = new QTreeWidgetItem(treeWidget, cities); planets->setText(0, tr("Planets"));
Each column in an item can have its own background brush which is set with the setBackground() function. The current background brush can be found with background(). The text label for each column can be rendered with its own font and brush. These are specified with the setFont() and setForeground() functions, and read with font() and foreground().
The main difference between top-level items and those in lower levels of the tree is that a top-level item has no parent(). This information can be used to tell the difference between items, and is useful to know when inserting and removing items from the tree. Children of an item can be removed with takeChild() and inserted at a given index in the list of children with the insertChild() function.
By default, items are enabled, selectable, checkable, and can be the source of a drag and drop operation. Each item's flags can be changed by calling setFlags() with the appropriate value (see Qt::ItemFlags). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.
Subclassing
When subclassing QTreeWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater than UserType.
See also QTreeWidget, QTreeWidgetItemIterator, Model/View Programming, QListWidgetItem, and QTableWidgetItem.
Member Type Documentation
enum QTreeWidgetItem::ChildIndicatorPolicy
Constant | Value | Description |
---|---|---|
QTreeWidgetItem::ShowIndicator | 0 | The controls for expanding and collapsing will be shown for this item even if there are no children. |
QTreeWidgetItem::DontShowIndicator | 1 | The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item. |
QTreeWidgetItem::DontShowIndicatorWhenChildless | 2 | The controls for expanding and collapsing will be shown if the item contains children. |
This enum was introduced or modified in Qt 4.3.
enum QTreeWidgetItem::ItemType
This enum describes the types that are used to describe tree widget items.
Constant | Value | Description |
---|---|---|
QTreeWidgetItem::Type | 0 | The default type for tree widget items. |
QTreeWidgetItem::UserType | 1000 | The minimum value for custom types. Values below UserType are reserved by Qt. |
You can define new user types in QTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.
See also type().
Member Function Documentation
QTreeWidgetItem::QTreeWidgetItem(int type = Type)
Constructs a tree widget item of the specified type. The item must be inserted into a tree widget.
See also type().
QTreeWidgetItem::QTreeWidgetItem(const QStringList &strings, int type = Type)
Constructs a tree widget item of the specified type. The item must be inserted into a tree widget. The given list of strings will be set as the item text for each column in the item.
See also type().
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, int type = Type)
Default constructs an instance of QTreeWidgetItem.
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, const QStringList &strings, int type = Type)
Default constructs an instance of QTreeWidgetItem.
QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, QTreeWidgetItem *after, int type = Type)
Default constructs an instance of QTreeWidgetItem.
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, int type = Type)
Constructs a tree widget item and append it to the given parent.
See also type().
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, const QStringList &strings, int type = Type)
Constructs a tree widget item and append it to the given parent. The given list of strings will be set as the item text for each column in the item.
See also type().
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, int type = Type)
Default constructs an instance of QTreeWidgetItem.
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().
This function was introduced in Qt 4.1.
[virtual]
QTreeWidgetItem::~QTreeWidgetItem()
Destroys this tree widget item.
The item will be removed from QTreeWidgets to which it has been added. This makes it safe to delete an item at any time.
void QTreeWidgetItem::addChild(QTreeWidgetItem *child)
Appends the child item to the list of children.
See also insertChild() and takeChild().
void QTreeWidgetItem::addChildren(const QList<QTreeWidgetItem *> &children)
Appends the given list of children to the item.
This function was introduced in Qt 4.1.
See also insertChildren() and takeChildren().
QBrush QTreeWidgetItem::background(int column) const
See also setBackground().
QColor QTreeWidgetItem::backgroundColor(int column) const
See also setBackgroundColor().
Qt::CheckState QTreeWidgetItem::checkState(int column) const
See also setCheckState().
QTreeWidgetItem *QTreeWidgetItem::child(int index) const
int QTreeWidgetItem::childCount() const
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().
[virtual]
QTreeWidgetItem *QTreeWidgetItem::clone() const
Creates a deep copy of the item and of its children.
int QTreeWidgetItem::columnCount() const
[virtual]
QVariant QTreeWidgetItem::data(int column, int role) const
Returns the value for the item's column and role.
See also setData().
[protected]
void QTreeWidgetItem::emitDataChanged()
Causes the model associated with this item to emit a dataChanged() signal for this item.
You normally only need to call this function if you have subclassed QTreeWidgetItem and reimplemented data() and/or setData().
This function was introduced in Qt 4.5.
See also setData().
Qt::ItemFlags QTreeWidgetItem::flags() const
See also setFlags().
QFont QTreeWidgetItem::font(int column) const
See also setFont().
QBrush QTreeWidgetItem::foreground(int column) const
See also setForeground().
QIcon QTreeWidgetItem::icon(int column) const
See also setIcon().
int QTreeWidgetItem::indexOfChild(QTreeWidgetItem *child) const
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.
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.
This function was introduced in Qt 4.1.
bool QTreeWidgetItem::isDisabled() const
bool QTreeWidgetItem::isExpanded() const
bool QTreeWidgetItem::isFirstColumnSpanned() const
bool QTreeWidgetItem::isHidden() const
bool QTreeWidgetItem::isSelected() const
QTreeWidgetItem *QTreeWidgetItem::parent() const
[virtual]
void QTreeWidgetItem::read(QDataStream &in)
Reads the item from stream in. This only reads data into a single item.
See also write().
void QTreeWidgetItem::removeChild(QTreeWidgetItem *child)
Removes the given item indicated by child. The removed item will not be deleted.
void QTreeWidgetItem::setBackground(int column, const QBrush &brush)
See also background().
void QTreeWidgetItem::setBackgroundColor(int column, const QColor &color)
See also backgroundColor().
void QTreeWidgetItem::setCheckState(int column, Qt::CheckState state)
See also checkState().
void QTreeWidgetItem::setChildIndicatorPolicy(QTreeWidgetItem::ChildIndicatorPolicy policy)
Sets the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown. The default value is ShowForChildren.
See also childIndicatorPolicy().
[virtual]
void QTreeWidgetItem::setData(int column, int role, const QVariant &value)
Sets the value for the item's column and role to the given value.
The role describes the type of data specified by value, and is defined by the Qt::ItemDataRole enum.
Note: The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data.
See also data().
void QTreeWidgetItem::setDisabled(bool disabled)
See also isDisabled().
void QTreeWidgetItem::setExpanded(bool expand)
See also isExpanded().
void QTreeWidgetItem::setFirstColumnSpanned(bool span)
See also isFirstColumnSpanned().
void QTreeWidgetItem::setFlags(Qt::ItemFlags flags)
See also flags().
void QTreeWidgetItem::setFont(int column, const QFont &font)
See also font().
void QTreeWidgetItem::setForeground(int column, const QBrush &brush)
See also foreground().
void QTreeWidgetItem::setHidden(bool hide)
See also isHidden().
void QTreeWidgetItem::setIcon(int column, const QIcon &icon)
See also icon().
void QTreeWidgetItem::setSelected(bool select)
See also isSelected().
void QTreeWidgetItem::setSizeHint(int column, const QSize &size)
See also sizeHint().
void QTreeWidgetItem::setStatusTip(int column, const QString &statusTip)
See also statusTip().
void QTreeWidgetItem::setText(int column, const QString &text)
See also text().
void QTreeWidgetItem::setTextAlignment(int column, int alignment)
See also textAlignment().
void QTreeWidgetItem::setTextColor(int column, const QColor &color)
See also textColor().
void QTreeWidgetItem::setToolTip(int column, const QString &toolTip)
See also toolTip().
void QTreeWidgetItem::setWhatsThis(int column, const QString &whatsThis)
See also whatsThis().
QSize QTreeWidgetItem::sizeHint(int column) const
See also setSizeHint().
void QTreeWidgetItem::sortChildren(int column, Qt::SortOrder order)
QString QTreeWidgetItem::statusTip(int column) const
See also setStatusTip().
QTreeWidgetItem *QTreeWidgetItem::takeChild(int index)
Removes the item at index and returns it, otherwise return 0.
QList<QTreeWidgetItem *> QTreeWidgetItem::takeChildren()
Removes the list of children and returns it, otherwise returns an empty list.
This function was introduced in Qt 4.1.
QString QTreeWidgetItem::text(int column) const
See also setText().
int QTreeWidgetItem::textAlignment(int column) const
See also setTextAlignment().
QColor QTreeWidgetItem::textColor(int column) const
See also setTextColor().
QString QTreeWidgetItem::toolTip(int column) const
See also setToolTip().
QTreeWidget *QTreeWidgetItem::treeWidget() const
int QTreeWidgetItem::type() const
QString QTreeWidgetItem::whatsThis(int column) const
See also setWhatsThis().
[virtual]
void QTreeWidgetItem::write(QDataStream &out) const
Writes the item to stream out. This only writes data from one single item.
See also read().
[virtual]
bool QTreeWidgetItem::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
.
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().
Related Non-Members
QDataStream &operator<<(QDataStream &out, const QTreeWidgetItem &item)
Writes the tree widget item item to stream out.
This operator uses QTreeWidgetItem::write().
See also Serializing Qt Data Types.
QDataStream &operator>>(QDataStream &in, QTreeWidgetItem &item)
Reads a tree widget item from stream in into item.
This operator uses QTreeWidgetItem::read().
See also Serializing Qt Data Types.