QTreeWidgetItem露
The
QTreeWidgetItemclass provides an item for use with theQTreeWidgetconvenience class. More鈥

Synopsis露
Functions露
def
addChild(child)def
addChildren(children)def
background(column)def
backgroundColor(column)def
checkState(column)def
child(index)def
childCount()def
childIndicatorPolicy()def
columnCount()def
emitDataChanged()def
flags()def
font(column)def
foreground(column)def
icon(column)def
indexOfChild(child)def
insertChild(index, child)def
insertChildren(index, children)def
isDisabled()def
isExpanded()def
isFirstColumnSpanned()def
isHidden()def
isSelected()def
parent()def
removeChild(child)def
setBackground(column, brush)def
setBackgroundColor(column, color)def
setCheckState(column, state)def
setChildIndicatorPolicy(policy)def
setDisabled(disabled)def
setExpanded(expand)def
setFirstColumnSpanned(span)def
setFlags(flags)def
setFont(column, font)def
setForeground(column, brush)def
setHidden(hide)def
setIcon(column, icon)def
setSelected(select)def
setSizeHint(column, size)def
setStatusTip(column, statusTip)def
setText(column, text)def
setTextAlignment(column, alignment)def
setTextColor(column, color)def
setToolTip(column, toolTip)def
setWhatsThis(column, whatsThis)def
sizeHint(column)def
sortChildren(column, order)def
statusTip(column)def
takeChild(index)def
takeChildren()def
text(column)def
textAlignment(column)def
textColor(column)def
toolTip(column)def
treeWidget()def
type()def
whatsThis(column)
Virtual functions露
Detailed Description露
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
QTreeWidgetItemclass is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with theQTreeWidgetclass.Items are usually constructed with a parent that is either a
QTreeWidget(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:cities = QTreeWidgetItem(treeWidget) cities.setText(0, tr("Cities")) osloItem = 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:
planets = 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 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 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 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鈥檚 flags can be changed by calling
setFlags()with the appropriate value (seeItemFlags). Checkable items can be checked and unchecked with thesetCheckState()function. The correspondingcheckState()function indicates whether the item is currently checked.
Subclassing露
When subclassing
QTreeWidgetItemto 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.
- class PySide2.QtWidgets.QTreeWidgetItem(treeview, after[, type=Type])露
PySide2.QtWidgets.QTreeWidgetItem(treeview, strings[, type=Type])
PySide2.QtWidgets.QTreeWidgetItem(treeview[, type=Type])
PySide2.QtWidgets.QTreeWidgetItem(parent, after[, type=Type])
PySide2.QtWidgets.QTreeWidgetItem(parent, strings[, type=Type])
PySide2.QtWidgets.QTreeWidgetItem(parent[, type=Type])
PySide2.QtWidgets.QTreeWidgetItem(strings[, type=Type])
PySide2.QtWidgets.QTreeWidgetItem(other)
PySide2.QtWidgets.QTreeWidgetItem([type=Type])
- param type:
int
- param parent:
- param strings:
list of strings
- param treeview:
- param after:
- param other:
Constructs a tree widget item of the specified
typeand inserts it into the givenparentafter theprecedingitem.See also
Constructs a tree widget item of the specified
typeand appends it to the items in the givenparent.See also
Constructs a tree widget item of the specified
typethat is inserted into theparentafter theprecedingchild item.See also
Constructs a tree widget item and append it to the given
parent.See also
Constructs a tree widget item of the specified
type. The item must be inserted into a tree widget.See also
- PySide2.QtWidgets.QTreeWidgetItem.ItemType露
This enum describes the types that are used to describe tree widget items.
Constant
Description
QTreeWidgetItem.Type
The default type for tree widget items.
QTreeWidgetItem.UserType
The minimum value for custom types. Values below are reserved by Qt.
You can define new user types in
QTreeWidgetItemsubclasses to ensure that custom items are treated specially; for example, when items are sorted.See also
- PySide2.QtWidgets.QTreeWidgetItem.ChildIndicatorPolicy露
Constant
Description
QTreeWidgetItem.ShowIndicator
The controls for expanding and collapsing will be shown for this item even if there are no children.
QTreeWidgetItem.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.
QTreeWidgetItem.DontShowIndicatorWhenChildless
The controls for expanding and collapsing will be shown if the item contains children.
- PySide2.QtWidgets.QTreeWidgetItem.addChild(child)露
- Parameters:
Appends the
childitem to the list of children.See also
- PySide2.QtWidgets.QTreeWidgetItem.addChildren(children)露
- Parameters:
children 鈥
Appends the given list of
childrento the item.See also
- PySide2.QtWidgets.QTreeWidgetItem.background(column)露
- Parameters:
column 鈥 int
- Return type:
Returns the brush used to render the background of the specified
column.See also
- PySide2.QtWidgets.QTreeWidgetItem.backgroundColor(column)露
- Parameters:
column 鈥 int
- Return type:
Note
This function is deprecated.
This function is deprecated. Use
background()instead.See also
- PySide2.QtWidgets.QTreeWidgetItem.checkState(column)露
- Parameters:
column 鈥 int
- Return type:
Returns the check state of the label in the given
column.See also
setCheckState()CheckState
- PySide2.QtWidgets.QTreeWidgetItem.child(index)露
- Parameters:
index 鈥 int
- Return type:
Returns the item at the given
indexin the list of the item鈥檚 children.See also
- PySide2.QtWidgets.QTreeWidgetItem.childCount()露
- Return type:
int
Returns the number of child items.
- PySide2.QtWidgets.QTreeWidgetItem.childIndicatorPolicy()露
- Return type:
Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.
See also
- PySide2.QtWidgets.QTreeWidgetItem.clone()露
- Return type:
Creates a deep copy of the item and of its children.
- PySide2.QtWidgets.QTreeWidgetItem.columnCount()露
- Return type:
int
Returns the number of columns in the item.
- PySide2.QtWidgets.QTreeWidgetItem.data(column, role)露
- Parameters:
column 鈥 int
role 鈥 int
- Return type:
object
Returns the value for the item鈥檚
columnandrole.See also
- PySide2.QtWidgets.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
QTreeWidgetItemand reimplementeddata()and/orsetData().See also
- PySide2.QtWidgets.QTreeWidgetItem.flags()露
- Return type:
ItemFlags
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
ItemIsSelectable|ItemIsUserCheckable|ItemIsEnabled|ItemIsDragEnabled|ItemIsDropEnabled.See also
- PySide2.QtWidgets.QTreeWidgetItem.font(column)露
- Parameters:
column 鈥 int
- Return type:
Returns the font used to render the text in the specified
column.See also
- PySide2.QtWidgets.QTreeWidgetItem.foreground(column)露
- Parameters:
column 鈥 int
- Return type:
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.See also
- PySide2.QtWidgets.QTreeWidgetItem.icon(column)露
- Parameters:
column 鈥 int
- Return type:
Returns the icon that is displayed in the specified
column.
- PySide2.QtWidgets.QTreeWidgetItem.indexOfChild(child)露
- Parameters:
- Return type:
int
Returns the index of the given
childin the item鈥檚 list of children.
- PySide2.QtWidgets.QTreeWidgetItem.insertChild(index, child)露
- Parameters:
index 鈥 int
Inserts the
childitem atindexin the list of children.If the child has already been inserted somewhere else it won鈥檛 be inserted again.
- PySide2.QtWidgets.QTreeWidgetItem.insertChildren(index, children)露
- Parameters:
index 鈥 int
children 鈥
Inserts the given list of
childreninto the list of the item children atindex.Children that have already been inserted somewhere else won鈥檛 be inserted.
- PySide2.QtWidgets.QTreeWidgetItem.isDisabled()露
- Return type:
bool
Returns
trueif the item is disabled; otherwise returnsfalse.See also
- PySide2.QtWidgets.QTreeWidgetItem.isExpanded()露
- Return type:
bool
Returns
trueif the item is expanded, otherwise returnsfalse.See also
- PySide2.QtWidgets.QTreeWidgetItem.isFirstColumnSpanned()露
- Return type:
bool
Returns
trueif the item is spanning all the columns in a row; otherwise returnsfalse.See also
- PySide2.QtWidgets.QTreeWidgetItem.isHidden()露
- Return type:
bool
Returns
trueif the item is hidden, otherwise returnsfalse.See also
- PySide2.QtWidgets.QTreeWidgetItem.isSelected()露
- Return type:
bool
Returns
trueif the item is selected, otherwise returnsfalse.See also
- PySide2.QtWidgets.QTreeWidgetItem.__lt__(other)露
- Parameters:
- Return type:
bool
- PySide2.QtWidgets.QTreeWidgetItem.parent()露
- Return type:
Returns the item鈥檚 parent.
See also
- PySide2.QtWidgets.QTreeWidgetItem.read(in)露
- Parameters:
Reads the item from stream
in. This only reads data into a single item.See also
- PySide2.QtWidgets.QTreeWidgetItem.removeChild(child)露
- Parameters:
Removes the given item indicated by
child. The removed item will not be deleted.
- PySide2.QtWidgets.QTreeWidgetItem.setBackground(column, brush)露
- Parameters:
column 鈥 int
brush 鈥
PySide2.QtGui.QBrush
Sets the background brush of the label in the given
columnto the specifiedbrush. Setting a default-constructed brush will let the view use the default color from the style.Note
If Qt Style Sheets are used on the same widget as , style sheets will take precedence if the settings conflict.
See also
- PySide2.QtWidgets.QTreeWidgetItem.setBackgroundColor(column, color)露
- Parameters:
column 鈥 int
color 鈥
PySide2.QtGui.QColor
Note
This function is deprecated.
This function is deprecated. Use
setBackground()instead.See also
- PySide2.QtWidgets.QTreeWidgetItem.setCheckState(column, state)露
- Parameters:
column 鈥 int
state 鈥
CheckState
Sets the item in the given
columncheck state to bestate.See also
- PySide2.QtWidgets.QTreeWidgetItem.setChildIndicatorPolicy(policy)露
- Parameters:
policy 鈥
ChildIndicatorPolicy
Sets the item indicator
policy. This policy decides when the tree branch expand/collapse indicator is shown. The default value isDontShowIndicatorWhenChildless.See also
- PySide2.QtWidgets.QTreeWidgetItem.setData(column, role, value)露
- Parameters:
column 鈥 int
role 鈥 int
value 鈥 object
Sets the value for the item鈥檚
columnandroleto the givenvalue.The
roledescribes the type of data specified byvalue, and is defined by theItemDataRoleenum.Note
The default implementation treats
EditRoleandDisplayRoleas referring to the same data.See also
- PySide2.QtWidgets.QTreeWidgetItem.setDisabled(disabled)露
- Parameters:
disabled 鈥 bool
Disables the item if
disabledis true; otherwise enables the item.See also
- PySide2.QtWidgets.QTreeWidgetItem.setExpanded(expand)露
- Parameters:
expand 鈥 bool
Expands the item if
expandis true, otherwise collapses the item.Warning
The
QTreeWidgetItemmust be added to theQTreeWidgetbefore calling this function.See also
- PySide2.QtWidgets.QTreeWidgetItem.setFirstColumnSpanned(span)露
- Parameters:
span 鈥 bool
Sets the first section to span all columns if
spanis true; otherwise all item sections are shown.See also
- PySide2.QtWidgets.QTreeWidgetItem.setFlags(flags)露
- Parameters:
flags 鈥
ItemFlags
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
- PySide2.QtWidgets.QTreeWidgetItem.setFont(column, font)露
- Parameters:
column 鈥 int
font 鈥
PySide2.QtGui.QFont
Sets the font used to display the text in the given
columnto the givenfont.See also
- PySide2.QtWidgets.QTreeWidgetItem.setForeground(column, brush)露
- Parameters:
column 鈥 int
brush 鈥
PySide2.QtGui.QBrush
Sets the foreground brush of the label in the given
columnto the specifiedbrush.See also
- PySide2.QtWidgets.QTreeWidgetItem.setHidden(hide)露
- Parameters:
hide 鈥 bool
Hides the item if
hideis true, otherwise shows the item.Note
A call to this function has no effect if the item is not currently in a view. In particular, calling
setHidden(true)on an item and only then adding it to a view will result in a visible item.See also
- PySide2.QtWidgets.QTreeWidgetItem.setIcon(column, icon)露
- Parameters:
column 鈥 int
icon 鈥
PySide2.QtGui.QIcon
Sets the icon to be displayed in the given
columntoicon.
- PySide2.QtWidgets.QTreeWidgetItem.setSelected(select)露
- Parameters:
select 鈥 bool
Sets the selected state of the item to
select.See also
- PySide2.QtWidgets.QTreeWidgetItem.setSizeHint(column, size)露
- Parameters:
column 鈥 int
size 鈥
PySide2.QtCore.QSize
Sets the size hint for the tree item in the given
columnto besize. If no size hint is set orsizeis invalid, the item delegate will compute the size hint based on the item data.See also
- PySide2.QtWidgets.QTreeWidgetItem.setStatusTip(column, statusTip)露
- Parameters:
column 鈥 int
statusTip 鈥 str
Sets the status tip for the given
columnto the givenstatusTip.QTreeWidgetmouse tracking needs to be enabled for this feature to work.See also
- PySide2.QtWidgets.QTreeWidgetItem.setText(column, text)露
- Parameters:
column 鈥 int
text 鈥 str
Sets the text to be displayed in the given
columnto the giventext.See also
- PySide2.QtWidgets.QTreeWidgetItem.setTextAlignment(column, alignment)露
- Parameters:
column 鈥 int
alignment 鈥 int
Sets the text alignment for the label in the given
columnto thealignmentspecified (seeAlignmentFlag).See also
- PySide2.QtWidgets.QTreeWidgetItem.setTextColor(column, color)露
- Parameters:
column 鈥 int
color 鈥
PySide2.QtGui.QColor
Note
This function is deprecated.
This function is deprecated. Use
setForeground()instead.See also
- PySide2.QtWidgets.QTreeWidgetItem.setToolTip(column, toolTip)露
- Parameters:
column 鈥 int
toolTip 鈥 str
Sets the tooltip for the given
columntotoolTip.See also
- PySide2.QtWidgets.QTreeWidgetItem.setWhatsThis(column, whatsThis)露
- Parameters:
column 鈥 int
whatsThis 鈥 str
Sets the 鈥淲hat鈥檚 This?鈥 help for the given
columntowhatsThis.See also
- PySide2.QtWidgets.QTreeWidgetItem.sizeHint(column)露
- Parameters:
column 鈥 int
- Return type:
Returns the size hint set for the tree item in the given
column(seeQSize).See also
- PySide2.QtWidgets.QTreeWidgetItem.sortChildren(column, order)露
- Parameters:
column 鈥 int
order 鈥
SortOrder
Sorts the children of the item using the given
order, by the values in the givencolumn.Note
This function does nothing if the item is not associated with a
QTreeWidget.
- PySide2.QtWidgets.QTreeWidgetItem.statusTip(column)露
- Parameters:
column 鈥 int
- Return type:
str
Returns the status tip for the contents of the given
column.See also
- PySide2.QtWidgets.QTreeWidgetItem.takeChild(index)露
- Parameters:
index 鈥 int
- Return type:
Removes the item at
indexand returns it, otherwise return 0.
- PySide2.QtWidgets.QTreeWidgetItem.takeChildren()露
- Return type:
Removes the list of children and returns it, otherwise returns an empty list.
- PySide2.QtWidgets.QTreeWidgetItem.text(column)露
- Parameters:
column 鈥 int
- Return type:
str
Returns the text in the specified
column.See also
- PySide2.QtWidgets.QTreeWidgetItem.textAlignment(column)露
- Parameters:
column 鈥 int
- Return type:
int
Returns the text alignment for the label in the given
column(seeAlignmentFlag).See also
- PySide2.QtWidgets.QTreeWidgetItem.textColor(column)露
- Parameters:
column 鈥 int
- Return type:
Note
This function is deprecated.
This function is deprecated. Use
foreground()instead.See also
- PySide2.QtWidgets.QTreeWidgetItem.toolTip(column)露
- Parameters:
column 鈥 int
- Return type:
str
Returns the tool tip for the given
column.See also
- PySide2.QtWidgets.QTreeWidgetItem.treeWidget()露
- Return type:
Returns the tree widget that contains the item.
- PySide2.QtWidgets.QTreeWidgetItem.type()露
- Return type:
int
Returns the type passed to the
QTreeWidgetItemconstructor.
- PySide2.QtWidgets.QTreeWidgetItem.whatsThis(column)露
- Parameters:
column 鈥 int
- Return type:
str
Returns the 鈥淲hat鈥檚 This?鈥 help for the contents of the given
column.See also
- PySide2.QtWidgets.QTreeWidgetItem.write(out)露
- Parameters:
Writes the item to stream
out. This only writes data from one single item.See also
漏 2022 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 the GNU 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.