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

Synopsis¶
Functions¶
def
addChild
(child)def
addChildren
(children)def
background
(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
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
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
toolTip
(column)def
treeWidget
()def
type
()def
whatsThis
(column)
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 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 = 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 function. The current background brush can be found with . The text label for each column can be rendered with its own font and brush. These are specified with the and functions, and read with and .
The main difference between top-level items and those in lower levels of the tree is that a top-level item has no . 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 with the appropriate value (see ItemFlags
). Checkable items can be checked and unchecked with the function. The corresponding 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
.
-
class
PySide6.QtWidgets.
QTreeWidgetItem
(treeview, after[, type=Type])¶ PySide6.QtWidgets.QTreeWidgetItem(treeview, strings[, type=Type])
PySide6.QtWidgets.QTreeWidgetItem(treeview[, type=Type])
PySide6.QtWidgets.QTreeWidgetItem(parent, after[, type=Type])
PySide6.QtWidgets.QTreeWidgetItem(parent, strings[, type=Type])
PySide6.QtWidgets.QTreeWidgetItem(parent[, type=Type])
PySide6.QtWidgets.QTreeWidgetItem(strings[, type=Type])
PySide6.QtWidgets.QTreeWidgetItem(other)
PySide6.QtWidgets.QTreeWidgetItem([type=Type])
- Parameters
strings – list of strings
parent –
PySide6.QtWidgets.QTreeWidgetItem
type – int
treeview –
PySide6.QtWidgets.QTreeWidget
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
-
PySide6.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 QTreeWidgetItem
subclasses to ensure that custom items are treated specially; for example, when items are sorted.
See also
-
PySide6.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.
-
PySide6.QtWidgets.QTreeWidgetItem.
addChild
(child)¶ - Parameters
Appends the child
item to the list of children.
See also
-
PySide6.QtWidgets.QTreeWidgetItem.
addChildren
(children)¶ - Parameters
children –
Appends the given list of children
to the item.
See also
-
PySide6.QtWidgets.QTreeWidgetItem.
background
(column)¶ - Parameters
column – int
- Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
checkState
(column)¶ - Parameters
column – int
- Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
child
(index)¶ - Parameters
index – int
- Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
childCount
()¶ - Return type
int
-
PySide6.QtWidgets.QTreeWidgetItem.
childIndicatorPolicy
()¶ - Return type
Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.
See also
-
PySide6.QtWidgets.QTreeWidgetItem.
clone
()¶ - Return type
Creates a deep copy of the item and of its children.
-
PySide6.QtWidgets.QTreeWidgetItem.
columnCount
()¶ - Return type
int
-
PySide6.QtWidgets.QTreeWidgetItem.
data
(column, role)¶ - Parameters
column – int
role – int
- Return type
object
Returns the value for the item’s column
and role
.
See also
-
PySide6.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 QTreeWidgetItem
and reimplemented data()
and/or setData()
.
See also
-
PySide6.QtWidgets.QTreeWidgetItem.
flags
()¶ - Return type
ItemFlags
-
PySide6.QtWidgets.QTreeWidgetItem.
font
(column)¶ - Parameters
column – int
- Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
foreground
(column)¶ - Parameters
column – int
- Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
icon
(column)¶ - Parameters
column – int
- Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
indexOfChild
(child)¶ - Parameters
- Return type
int
-
PySide6.QtWidgets.QTreeWidgetItem.
insertChild
(index, child)¶ - Parameters
index – int
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.
-
PySide6.QtWidgets.QTreeWidgetItem.
insertChildren
(index, children)¶ - Parameters
index – int
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.
-
PySide6.QtWidgets.QTreeWidgetItem.
isDisabled
()¶ - Return type
bool
-
PySide6.QtWidgets.QTreeWidgetItem.
isExpanded
()¶ - Return type
bool
-
PySide6.QtWidgets.QTreeWidgetItem.
isFirstColumnSpanned
()¶ - Return type
bool
-
PySide6.QtWidgets.QTreeWidgetItem.
isHidden
()¶ - Return type
bool
-
PySide6.QtWidgets.QTreeWidgetItem.
isSelected
()¶ - Return type
bool
-
PySide6.QtWidgets.QTreeWidgetItem.
__lt__
(other)¶ - Parameters
- Return type
bool
-
PySide6.QtWidgets.QTreeWidgetItem.
parent
()¶ - Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
read
(in)¶ - Parameters
Reads the item from stream in
. This only reads data into a single item.
See also
-
PySide6.QtWidgets.QTreeWidgetItem.
removeChild
(child)¶ - Parameters
Removes the given item indicated by child
. The removed item will not be deleted.
-
PySide6.QtWidgets.QTreeWidgetItem.
setBackground
(column, brush)¶ - Parameters
column – int
brush –
PySide6.QtGui.QBrush
-
PySide6.QtWidgets.QTreeWidgetItem.
setCheckState
(column, state)¶ - Parameters
column – int
state –
CheckState
-
PySide6.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 is DontShowIndicatorWhenChildless
.
See also
-
PySide6.QtWidgets.QTreeWidgetItem.
setData
(column, role, value)¶ - Parameters
column – int
role – int
value – object
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 ItemDataRole
enum.
Note
The default implementation treats EditRole
and DisplayRole
as referring to the same data.
See also
-
PySide6.QtWidgets.QTreeWidgetItem.
setDisabled
(disabled)¶ - Parameters
disabled – bool
-
PySide6.QtWidgets.QTreeWidgetItem.
setExpanded
(expand)¶ - Parameters
expand – bool
-
PySide6.QtWidgets.QTreeWidgetItem.
setFirstColumnSpanned
(span)¶ - Parameters
span – bool
-
PySide6.QtWidgets.QTreeWidgetItem.
setFlags
(flags)¶ - Parameters
flags –
ItemFlags
-
PySide6.QtWidgets.QTreeWidgetItem.
setFont
(column, font)¶ - Parameters
column – int
font –
PySide6.QtGui.QFont
-
PySide6.QtWidgets.QTreeWidgetItem.
setForeground
(column, brush)¶ - Parameters
column – int
brush –
PySide6.QtGui.QBrush
-
PySide6.QtWidgets.QTreeWidgetItem.
setHidden
(hide)¶ - Parameters
hide – bool
-
PySide6.QtWidgets.QTreeWidgetItem.
setIcon
(column, icon)¶ - Parameters
column – int
icon –
PySide6.QtGui.QIcon
-
PySide6.QtWidgets.QTreeWidgetItem.
setSelected
(select)¶ - Parameters
select – bool
-
PySide6.QtWidgets.QTreeWidgetItem.
setSizeHint
(column, size)¶ - Parameters
column – int
size –
PySide6.QtCore.QSize
-
PySide6.QtWidgets.QTreeWidgetItem.
setStatusTip
(column, statusTip)¶ - Parameters
column – int
statusTip – str
-
PySide6.QtWidgets.QTreeWidgetItem.
setText
(column, text)¶ - Parameters
column – int
text – str
-
PySide6.QtWidgets.QTreeWidgetItem.
setTextAlignment
(column, alignment)¶ - Parameters
column – int
alignment – int
-
PySide6.QtWidgets.QTreeWidgetItem.
setToolTip
(column, toolTip)¶ - Parameters
column – int
toolTip – str
-
PySide6.QtWidgets.QTreeWidgetItem.
setWhatsThis
(column, whatsThis)¶ - Parameters
column – int
whatsThis – str
-
PySide6.QtWidgets.QTreeWidgetItem.
sizeHint
(column)¶ - Parameters
column – int
- Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
sortChildren
(column, order)¶ - Parameters
column – int
order –
SortOrder
-
PySide6.QtWidgets.QTreeWidgetItem.
statusTip
(column)¶ - Parameters
column – int
- Return type
str
-
PySide6.QtWidgets.QTreeWidgetItem.
takeChild
(index)¶ - Parameters
index – int
- Return type
Removes the item at index
and returns it, otherwise return 0.
-
PySide6.QtWidgets.QTreeWidgetItem.
takeChildren
()¶ - Return type
Removes the list of children and returns it, otherwise returns an empty list.
-
PySide6.QtWidgets.QTreeWidgetItem.
text
(column)¶ - Parameters
column – int
- Return type
str
-
PySide6.QtWidgets.QTreeWidgetItem.
textAlignment
(column)¶ - Parameters
column – int
- Return type
int
-
PySide6.QtWidgets.QTreeWidgetItem.
toolTip
(column)¶ - Parameters
column – int
- Return type
str
-
PySide6.QtWidgets.QTreeWidgetItem.
treeWidget
()¶ - Return type
-
PySide6.QtWidgets.QTreeWidgetItem.
type
()¶ - Return type
int
-
PySide6.QtWidgets.QTreeWidgetItem.
whatsThis
(column)¶ - Parameters
column – int
- Return type
str
-
PySide6.QtWidgets.QTreeWidgetItem.
write
(out)¶ - Parameters
Writes the item to stream out
. This only writes data from one single item.
See also
© 2021 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.