PySide6.QtWidgets.QTreeWidgetItem¶
- class QTreeWidgetItem¶
The
QTreeWidgetItem
class provides an item for use with theQTreeWidget
convenience class. More…Synopsis¶
Methods¶
def
__init__()
def
addChild()
def
addChildren()
def
background()
def
checkState()
def
child()
def
childCount()
def
columnCount()
def
flags()
def
font()
def
foreground()
def
icon()
def
indexOfChild()
def
insertChild()
def
insertChildren()
def
isDisabled()
def
isExpanded()
def
isHidden()
def
isSelected()
def
parent()
def
removeChild()
def
setBackground()
def
setCheckState()
def
setDisabled()
def
setExpanded()
def
setFlags()
def
setFont()
def
setForeground()
def
setHidden()
def
setIcon()
def
setSelected()
def
setSizeHint()
def
setStatusTip()
def
setText()
def
setToolTip()
def
setWhatsThis()
def
sizeHint()
def
sortChildren()
def
statusTip()
def
takeChild()
def
takeChildren()
def
text()
def
textAlignment()
def
toolTip()
def
treeWidget()
def
type()
def
whatsThis()
Virtual methods¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 theQTreeWidget
class.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’s flags can be changed by calling
setFlags()
with the appropriate value (see Qt::ItemFlags). Checkable items can be checked and unchecked with thesetCheckState()
function. The correspondingcheckState()
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 thanUserType
.- class ItemType¶
(inherits
enum.IntEnum
) 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 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
- class 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.
- __init__(other)¶
- Parameters:
other –
QTreeWidgetItem
Constructs a copy of
other
. Note thattype()
andtreeWidget()
are not copied.This function is useful when reimplementing
clone()
.- __init__([type=QTreeWidgetItem.ItemType.Type])
- Parameters:
type – int
Constructs a tree widget item of the specified
type
. The item must be inserted into a tree widget.See also
- __init__(treeview[, type=QTreeWidgetItem.ItemType.Type])
- Parameters:
treeview –
QTreeWidget
type – int
Constructs a tree widget item of the specified
type
and appends it to the items in the givenparent
.See also
- __init__(parent[, type=QTreeWidgetItem.ItemType.Type])
- Parameters:
parent –
QTreeWidgetItem
type – int
Constructs a tree widget item and append it to the given
parent
.See also
- __init__(strings[, type=QTreeWidgetItem.ItemType.Type])
- Parameters:
strings – list of strings
type – int
Constructs a tree widget item of the specified
type
. 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 also
- __init__(treeview, after[, type=QTreeWidgetItem.ItemType.Type])
- Parameters:
treeview –
QTreeWidget
after –
QTreeWidgetItem
type – int
Constructs a tree widget item of the specified
type
and inserts it into the givenparent
after thepreceding
item.See also
- __init__(treeview, strings[, type=QTreeWidgetItem.ItemType.Type])
- Parameters:
treeview –
QTreeWidget
strings – list of strings
type – int
Constructs a tree widget item of the specified
type
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 also
- __init__(parent, after[, type=QTreeWidgetItem.ItemType.Type])
- Parameters:
parent –
QTreeWidgetItem
after –
QTreeWidgetItem
type – int
Constructs a tree widget item of the specified
type
that is inserted into theparent
after thepreceding
child item.See also
- __init__(parent, strings[, type=QTreeWidgetItem.ItemType.Type])
- Parameters:
parent –
QTreeWidgetItem
strings – list of strings
type – int
Constructs a tree widget item and append it to the given
parent
. The given list ofstrings
will be set as the item text for each column in the item.See also
- addChild(child)¶
- Parameters:
child –
QTreeWidgetItem
Appends the
child
item to the list of children.See also
- addChildren(children)¶
- Parameters:
children – .list of QTreeWidgetItem
Appends the given list of
children
to the item.See also
Returns the brush used to render the background of the specified
column
.See also
- checkState(column)¶
- Parameters:
column – int
- Return type:
Returns the check state of the label in the given
column
.See also
setCheckState()
CheckState
- child(index)¶
- Parameters:
index – int
- Return type:
Returns the item at the given
index
in the list of the item’s children.See also
- childCount()¶
- Return type:
int
Returns the number of child items.
- childIndicatorPolicy()¶
- Return type:
Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.
See also
- clone()¶
- Return type:
Creates a deep copy of the item and of its children.
- columnCount()¶
- Return type:
int
Returns the number of columns in the item.
- data(column, role)¶
- Parameters:
column – int
role – int
- Return type:
object
Returns the value for the item’s
column
androle
.See also
- 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 reimplementeddata()
and/orsetData()
.See also
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.
See also
Returns the font used to render the text in the specified
column
.See also
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
Returns the icon that is displayed in the specified
column
.- indexOfChild(child)¶
- Parameters:
child –
QTreeWidgetItem
- Return type:
int
Returns the index of the given
child
in the item’s list of children.- insertChild(index, child)¶
- Parameters:
index – int
child –
QTreeWidgetItem
Inserts the
child
item atindex
in the list of children.If the child has already been inserted somewhere else it won’t be inserted again.
- insertChildren(index, children)¶
- Parameters:
index – int
children – .list of QTreeWidgetItem
Inserts the given list of
children
into the list of the item children atindex
.Children that have already been inserted somewhere else won’t be inserted.
- isDisabled()¶
- Return type:
bool
Returns
true
if the item is disabled; otherwise returnsfalse
.See also
- isExpanded()¶
- Return type:
bool
Returns
true
if the item is expanded, otherwise returnsfalse
.See also
- isFirstColumnSpanned()¶
- Return type:
bool
Returns
true
if the item is spanning all the columns in a row; otherwise returnsfalse
.See also
- isHidden()¶
- Return type:
bool
Returns
true
if the item is hidden, otherwise returnsfalse
.See also
- isSelected()¶
- Return type:
bool
Returns
true
if the item is selected, otherwise returnsfalse
.See also
- __lt__(other)¶
- Parameters:
other –
QTreeWidgetItem
- Return type:
bool
Returns
true
if the text in the item is less than the text in theother
item, otherwise returnsfalse
.- parent()¶
- Return type:
Returns the item’s parent.
See also
- read(in)¶
- Parameters:
in –
QDataStream
Reads the item from stream
in
. This only reads data into a single item.See also
- removeChild(child)¶
- Parameters:
child –
QTreeWidgetItem
Removes the given item indicated by
child
. The removed item will not be deleted.Sets the background brush of the label in the given
column
to 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 setBackground(), style sheets will take precedence if the settings conflict.
See also
- setCheckState(column, state)¶
- Parameters:
column – int
state –
CheckState
Sets the item in the given
column
check state to bestate
.See also
- 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
- setData(column, role, value)¶
- Parameters:
column – int
role – int
value – object
Sets the value for the item’s
column
androle
to the givenvalue
.The
role
describes the type of data specified byvalue
, 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
- setDisabled(disabled)¶
- Parameters:
disabled – bool
Disables the item if
disabled
is true; otherwise enables the item.See also
- setExpanded(expand)¶
- Parameters:
expand – bool
Expands the item if
expand
is true, otherwise collapses the item.- setFirstColumnSpanned(span)¶
- Parameters:
span – bool
Sets the first section to span all columns if
span
is true; otherwise all item sections are shown.See also
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
Sets the font used to display the text in the given
column
to the givenfont
.See also
Sets the foreground brush of the label in the given
column
to the specifiedbrush
.See also
- setHidden(hide)¶
- Parameters:
hide – bool
Hides the item if
hide
is 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
Sets the icon to be displayed in the given
column
toicon
.- setSelected(select)¶
- Parameters:
select – bool
Sets the selected state of the item to
select
.See also
Sets the size hint for the tree item in the given
column
to besize
. If no size hint is set orsize
is invalid, the item delegate will compute the size hint based on the item data.See also
- setStatusTip(column, statusTip)¶
- Parameters:
column – int
statusTip – str
Sets the status tip for the given
column
to the givenstatusTip
.QTreeWidget
mouse tracking needs to be enabled for this feature to work.See also
- setText(column, text)¶
- Parameters:
column – int
text – str
Sets the text to be displayed in the given
column
to the giventext
.See also
- setTextAlignment(column, alignment)¶
- Parameters:
column – int
alignment – Combination of
AlignmentFlag
Sets the text alignment for the label in the given
column
to thealignment
specified.See also
- setTextAlignment(column, alignment)
- Parameters:
column – int
alignment –
AlignmentFlag
- setTextAlignment(column, alignment)
- Parameters:
column – int
alignment – int
Note
This function is deprecated.
Use the overload that takes a Qt::Alignment argument.
Sets the text alignment for the label in the given
column
to thealignment
specified.See also
Alignment
- setToolTip(column, toolTip)¶
- Parameters:
column – int
toolTip – str
Sets the tooltip for the given
column
totoolTip
.See also
- setWhatsThis(column, whatsThis)¶
- Parameters:
column – int
whatsThis – str
Sets the “What’s This?” help for the given
column
towhatsThis
.See also
Returns the size hint set for the tree item in the given
column
(see QSize).See also
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
.- statusTip(column)¶
- Parameters:
column – int
- Return type:
str
Returns the status tip for the contents of the given
column
.See also
- takeChild(index)¶
- Parameters:
index – int
- Return type:
Removes the item at
index
and returns it, otherwise return 0.- takeChildren()¶
- Return type:
.list of QTreeWidgetItem
Removes the list of children and returns it, otherwise returns an empty list.
- text(column)¶
- Parameters:
column – int
- Return type:
str
Returns the text in the specified
column
.See also
- textAlignment(column)¶
- Parameters:
column – int
- Return type:
int
Returns the text alignment for the label in the given
column
.Note
This function returns an int for historical reasons. It will be corrected to return Qt::Alignment in Qt 7.
See also
setTextAlignment()
Alignment
- toolTip(column)¶
- Parameters:
column – int
- Return type:
str
Returns the tool tip for the given
column
.See also
- treeWidget()¶
- Return type:
Returns the tree widget that contains the item.
- type()¶
- Return type:
int
Returns the type passed to the
QTreeWidgetItem
constructor.- whatsThis(column)¶
- Parameters:
column – int
- Return type:
str
Returns the “What’s This?” help for the contents of the given
column
.See also
- write(out)¶
- Parameters:
out –
QDataStream
Writes the item to stream
out
. This only writes data from one single item.See also