
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQTreeWidgetItem class provides an item for use with theQTreeWidget convenience class.More...
| Header: | #include <QTreeWidgetItem> |
| enum | ChildIndicatorPolicy { ShowIndicator, DontShowIndicator, DontShowIndicatorWhenChildless } |
| enum | ItemType { Type, UserType } |
| QTreeWidgetItem(int type = Type) | |
| QTreeWidgetItem(const QStringList & strings, int type = Type) | |
| QTreeWidgetItem(QTreeWidget * parent, int type = Type) | |
| QTreeWidgetItem(QTreeWidget * parent, const QStringList & strings, int type = Type) | |
| QTreeWidgetItem(QTreeWidget * parent, QTreeWidgetItem * preceding, int type = Type) | |
| QTreeWidgetItem(QTreeWidgetItem * parent, int type = Type) | |
| QTreeWidgetItem(QTreeWidgetItem * parent, const QStringList & strings, int type = Type) | |
| QTreeWidgetItem(QTreeWidgetItem * parent, QTreeWidgetItem * preceding, int type = Type) | |
| QTreeWidgetItem(const QTreeWidgetItem & other) | |
| virtual | ~QTreeWidgetItem() |
| void | addChild(QTreeWidgetItem * child) |
| void | addChildren(const QList<QTreeWidgetItem *> & children) |
| QBrush | background(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 | 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 | 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 |
| 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) |
| void | emitDataChanged() |
| QDataStream & | operator<<(QDataStream & out, const QTreeWidgetItem & item) |
| QDataStream & | operator>>(QDataStream & in, QTreeWidgetItem & item) |
TheQTreeWidgetItem class provides an item for use with theQTreeWidget 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.
TheQTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with theQTreeWidget class.
Items are usually constructed with a parent that is either aQTreeWidget (for top-level items) or aQTreeWidgetItem (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=newQTreeWidgetItem(treeWidget); cities->setText(0, tr("Cities"));QTreeWidgetItem*osloItem=newQTreeWidgetItem(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=newQTreeWidgetItem(treeWidget, cities); planets->setText(0, tr("Planets"));
Each column in an item can have its own background brush which is set with thesetBackground() function. The current background brush can be found withbackground(). The text label for each column can be rendered with its own font and brush. These are specified with thesetFont() andsetForeground() functions, and read withfont() andforeground().
The main difference between top-level items and those in lower levels of the tree is that a top-level item has noparent(). 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 withtakeChild() and inserted at a given index in the list of children with theinsertChild() 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 callingsetFlags() with the appropriate value (seeQt::ItemFlags). Checkable items can be checked and unchecked with thesetCheckState() function. The correspondingcheckState() function indicates whether the item is currently checked.
When subclassingQTreeWidgetItem 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 thanUserType.
See alsoQTreeWidget,QTreeWidgetItemIterator,Model/View Programming,QListWidgetItem, andQTableWidgetItem.
| 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.
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 inQTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.
See alsotype().
Constructs a tree widget item of the specifiedtype. The item must be inserted into a tree widget.
See alsotype().
Constructs a tree widget item of the specifiedtype. The item must be inserted into a tree widget. The given list ofstrings will be set as the item text for each column in the item.
See alsotype().
Constructs a tree widget item of the specifiedtype and appends it to the items in the givenparent.
See alsotype().
Constructs a tree widget item of the specifiedtype and appends it to the items in the givenparent. The given list ofstrings will be set as the item text for each column in the item.
See alsotype().
Constructs a tree widget item of the specifiedtype and inserts it into the givenparent after thepreceding item.
See alsotype().
Constructs a tree widget item and append it to the givenparent.
See alsotype().
Constructs a tree widget item and append it to the givenparent. The given list ofstrings will be set as the item text for each column in the item.
See alsotype().
Constructs a tree widget item of the specifiedtype that is inserted into theparent after thepreceding child item.
See alsotype().
Constructs a copy ofother. Note thattype() andtreeWidget() are not copied.
This function is useful when reimplementingclone().
This function was introduced in Qt 4.1.
[virtual]QTreeWidgetItem::~QTreeWidgetItem()Destroys this tree widget item.
The item will be removed fromQTreeWidgets to which it has been added. This makes it safe to delete an item at any time.
Appends thechild item to the list of children.
See alsoinsertChild() andtakeChild().
Appends the given list ofchildren to the item.
This function was introduced in Qt 4.1.
See alsoinsertChildren() andtakeChildren().
Returns the brush used to render the background of the specifiedcolumn.
This function was introduced in Qt 4.2.
See alsosetBackground() andforeground().
Returns the check state of the label in the givencolumn.
See alsosetCheckState() andQt::CheckState.
Returns the item at the givenindex in the list of the item's children.
See alsoparent().
Returns the number of child items.
Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.
See alsosetChildIndicatorPolicy().
[virtual]QTreeWidgetItem * QTreeWidgetItem::clone() constCreates a deep copy of the item and of its children.
Returns the number of columns in the item.
[virtual]QVariant QTreeWidgetItem::data(int column,int role) constReturns the value for the item'scolumn androle.
See alsosetData().
[protected]void QTreeWidgetItem::emitDataChanged()Causes the model associated with this item to emit adataChanged() signal for this item.
You normally only need to call this function if you have subclassedQTreeWidgetItem and reimplementeddata() and/orsetData().
This function was introduced in Qt 4.5.
See alsosetData().
Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.
The default value for flags isQt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled. If the item was constructed with a parent, flags will in addition containQt::ItemIsDropEnabled.
See alsosetFlags().
Returns the font used to render the text in the specifiedcolumn.
See alsosetFont().
Returns the brush used to render the foreground (e.g. text) of the specifiedcolumn.
This function was introduced in Qt 4.2.
See alsosetForeground() andbackground().
Returns the icon that is displayed in the specifiedcolumn.
See alsosetIcon() andiconSize.
Returns the index of the givenchild in the item's list of children.
Inserts thechild item atindex in the list of children.
If the child has already been inserted somewhere else it wont be inserted again.
Inserts the given list ofchildren into the list of the item children atindex .
Children that have already been inserted somewhere else wont be inserted.
This function was introduced in Qt 4.1.
Returns true if the item is disabled; otherwise returns false.
This function was introduced in Qt 4.3.
See alsosetFlags().
Returns true if the item is expanded, otherwise returns false.
This function was introduced in Qt 4.2.
See alsosetExpanded().
Returns true if the item is spanning all the columns in a row; otherwise returns false.
This function was introduced in Qt 4.3.
See alsosetFirstColumnSpanned().
Returns true if the item is hidden, otherwise returns false.
This function was introduced in Qt 4.2.
See alsosetHidden().
Returns true if the item is selected, otherwise returns false.
This function was introduced in Qt 4.2.
See alsosetSelected().
Returns the item's parent.
See alsochild().
[virtual]void QTreeWidgetItem::read(QDataStream & in)Reads the item from streamin. This only reads data into a single item.
See alsowrite().
Removes the given item indicated bychild. The removed item will not be deleted.
Sets the background brush of the label in the givencolumn to the specifiedbrush.
This function was introduced in Qt 4.2.
See alsobackground() andsetForeground().
Sets the item in the givencolumn check state to bestate.
See alsocheckState().
Sets the item indicatorpolicy. This policy decides when the tree branch expand/collapse indicator is shown. The default value is ShowForChildren.
See alsochildIndicatorPolicy().
[virtual]void QTreeWidgetItem::setData(int column,int role, constQVariant & value)Sets the value for the item'scolumn androle to the givenvalue.
Therole describes the type of data specified byvalue, and is defined by theQt::ItemDataRole enum.
See alsodata().
Disables the item ifdisabled is true; otherwise enables the item.
This function was introduced in Qt 4.3.
See alsoisDisabled() andsetFlags().
Expands the item ifexpand is true, otherwise collapses the item.
Warning: TheQTreeWidgetItem must be added to theQTreeWidget before calling this function.
This function was introduced in Qt 4.2.
See alsoisExpanded().
Sets the first section to span all columns ifspan is true; otherwise all item sections are shown.
This function was introduced in Qt 4.3.
See alsoisFirstColumnSpanned().
Sets the flags for the item to the givenflags. These determine whether the item can be selected or modified. This is often used to disable an item.
See alsoflags().
Sets the font used to display the text in the givencolumn to the givenfont.
See alsofont(),setText(), andsetForeground().
Sets the foreground brush of the label in the givencolumn to the specifiedbrush.
This function was introduced in Qt 4.2.
See alsoforeground() andsetBackground().
Hides the item ifhide is true, otherwise shows the item.
This function was introduced in Qt 4.2.
See alsoisHidden().
Sets the icon to be displayed in the givencolumn toicon.
See alsoicon(),setText(), andiconSize.
Sets the selected state of the item toselect.
This function was introduced in Qt 4.2.
See alsoisSelected().
Sets the size hint for the tree item in the givencolumn to besize. If no size hint is set, the item delegate will compute the size hint based on the item data.
This function was introduced in Qt 4.1.
See alsosizeHint().
Sets the status tip for the givencolumn to the givenstatusTip.QTreeWidget mouse tracking needs to be enabled for this feature to work.
See alsostatusTip(),setToolTip(), andsetWhatsThis().
Sets the text to be displayed in the givencolumn to the giventext.
See alsotext(),setFont(), andsetForeground().
Sets the text alignment for the label in the givencolumn to thealignment specified (seeQt::AlignmentFlag).
See alsotextAlignment().
Sets the tooltip for the givencolumn totoolTip.
See alsotoolTip(),setStatusTip(), andsetWhatsThis().
Sets the "What's This?" help for the givencolumn towhatsThis.
See alsowhatsThis(),setStatusTip(), andsetToolTip().
Returns the size hint set for the tree item in the givencolumn (seeQSize).
This function was introduced in Qt 4.1.
See alsosetSizeHint().
Sorts the children of the item using the givenorder, by the values in the givencolumn.
Note:This function does nothing if the item is not associated with aQTreeWidget.
This function was introduced in Qt 4.2.
Returns the status tip for the contents of the givencolumn.
See alsosetStatusTip().
Removes the item atindex and returns it, otherwise return 0.
Removes the list of children and returns it, otherwise returns an empty list.
This function was introduced in Qt 4.1.
Returns the text in the specifiedcolumn.
See alsosetText().
Returns the text alignment for the label in the givencolumn (seeQt::AlignmentFlag).
See alsosetTextAlignment().
Returns the tool tip for the givencolumn.
See alsosetToolTip().
Returns the tree widget that contains the item.
Returns the type passed to theQTreeWidgetItem constructor.
Returns the "What's This?" help for the contents of the givencolumn.
See alsosetWhatsThis().
[virtual]void QTreeWidgetItem::write(QDataStream & out) constWrites the item to streamout. This only writes data from one single item.
See alsoread().
[virtual]bool QTreeWidgetItem::operator<(constQTreeWidgetItem & other) constReturns true if the text in the item is less than the text in theother item, otherwise returns false.
Assignsother's data and flags to this item. Note thattype() andtreeWidget() are not copied.
This function is useful when reimplementingclone().
Writes the tree widget itemitem to streamout.
This operator usesQTreeWidgetItem::write().
See alsoSerializing Qt Data Types.
Reads a tree widget item from streamin intoitem.
This operator usesQTreeWidgetItem::read().
See alsoSerializing Qt Data Types.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.