QTreeWidgetItem Class Reference

[ QtGui module]

QTreeWidgetItem 类提供项为用于 QTreeWidget 方便类。 更多...

类型

方法

Special Methods


详细描述

QTreeWidgetItem 类提供项为用于 QTreeWidget 方便类。

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 类。

项构造通常采用的父级要么是 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 () 函数。 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 () 和 setForeground () functions, and read with font () 和 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 () 函数。

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 值 (见 Qt.ItemFlags ). Checkable items can be checked and unchecked with the setCheckState () 函数。 The corresponding checkState () function indicates whether the item is currently checked.

子类化

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 .


类型文档编制

QTreeWidgetItem.ChildIndicatorPolicy

常量 描述
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.

该枚举在 Qt 4.3 引入或被修改。

QTreeWidgetItem.ItemType

This enum describes the types that are used to describe tree widget items.

常量 描述
QTreeWidgetItem.Type 0 用于树 Widget 项的默认类型。
QTreeWidgetItem.UserType 1000 The minimum value for custom types. Values below UserType are reserved by Qt.

可以定义新用户类型在 QTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

另请参阅 type ().


方法文档编制

QTreeWidgetItem.__init__ ( self , int  type  = QTreeWidgetItem.Type)

构造树 Widget 项采用指定 type 。 item must be inserted into a tree widget.

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QStringList  strings , int  type  = QTreeWidgetItem.Type)

构造树 Widget 项采用指定 type 。 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 项。

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QTreeWidget   parent , int  type  = QTreeWidgetItem.Type)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造树 Widget 项采用指定 type and appends it to the items in the given parent .

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QTreeWidget   parent , QStringList  strings , int  type  = QTreeWidgetItem.Type)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造树 Widget 项采用指定 type and appends it to the items in the given parent . The given list of strings will be set as the item text for each column in the item.

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QTreeWidget   parent , QTreeWidgetItem   preceding , int  type  = QTreeWidgetItem.Type)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造树 Widget 项采用指定 type and inserts it into the given parent 后于 preceding 项。

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QTreeWidgetItem   parent , int  type  = QTreeWidgetItem.Type)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造树 Widget 项并将其追加到给定 parent .

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QTreeWidgetItem   parent , QStringList  strings , int  type  = QTreeWidgetItem.Type)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造树 Widget 项并将其追加到给定 parent 。给定列表 strings will be set as the item text for each column in the item.

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QTreeWidgetItem   parent , QTreeWidgetItem   preceding , int  type  = QTreeWidgetItem.Type)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造树 Widget 项采用指定 type that is inserted into the parent 后于 preceding child 项。

另请参阅 type ().

QTreeWidgetItem.__init__ ( self , QTreeWidgetItem   other )

构造副本为 other 。注意 type () 和 treeWidget () are not copied.

此函数是有用的,当重实现 clone ().

该函数在 Qt 4.1 引入。

另请参阅 data () and flags ().

QTreeWidgetItem.addChild ( self , QTreeWidgetItem   child )

child argument has it's ownership transferred to Qt.

追加 child 项到子级列表。

另请参阅 insertChild () 和 takeChild ().

QTreeWidgetItem.addChildren ( self , list-of-QTreeWidgetItem  children )

children argument has it's ownership transferred to Qt.

追加给定列表 children 到项。

该函数在 Qt 4.1 引入。

另请参阅 insertChildren () 和 takeChildren ().

QBrush QTreeWidgetItem.background ( self , int  column )

Returns the brush used to render the background of the specified column .

该函数在 Qt 4.2 引入。

另请参阅 setBackground () 和 foreground ().

QColor QTreeWidgetItem.backgroundColor ( self , int  column )

Qt.CheckState QTreeWidgetItem.checkState ( self , int  column )

返回标签的校验状态在给定 column .

另请参阅 setCheckState () 和 Qt.CheckState .

QTreeWidgetItem QTreeWidgetItem.child ( self , int  index )

返回项位于给定 index in the list of the item's children.

另请参阅 parent ().

int QTreeWidgetItem.childCount ( self )

返回子级项数。

ChildIndicatorPolicy QTreeWidgetItem.childIndicatorPolicy ( self )

Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.

另请参阅 setChildIndicatorPolicy ().

QTreeWidgetItem QTreeWidgetItem.clone ( self )

Creates a deep copy of the item and of its children.

int QTreeWidgetItem.columnCount ( self )

返回项中的列数。

QVariant QTreeWidgetItem.data ( self , int  column , int  role )

Returns the value for the item's column and role .

另请参阅 setData ().

QTreeWidgetItem.emitDataChanged ( self )

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 ().

该函数在 Qt 4.5 引入。

另请参阅 setData ().

Qt.ItemFlags QTreeWidgetItem.flags ( self )

Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.

标志的默认值为 Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled . If the item was constructed with a parent, flags will in addition contain Qt.ItemIsDropEnabled .

另请参阅 setFlags ().

QFont QTreeWidgetItem.font ( self , int  column )

返回用于渲染文本的字体在指定 column .

另请参阅 setFont ().

QBrush QTreeWidgetItem.foreground ( self , int  column )

Returns the brush used to render the foreground (e.g. text) of the specified column .

该函数在 Qt 4.2 引入。

另请参阅 setForeground () 和 background ().

QIcon QTreeWidgetItem.icon ( self , int  column )

Returns the icon that is displayed in the specified column .

另请参阅 setIcon () 和 iconSize .

int QTreeWidgetItem.indexOfChild ( self , QTreeWidgetItem   achild )

Returns the index of the given child in the item's list of children.

QTreeWidgetItem.insertChild ( self , int  index , QTreeWidgetItem   child )

child argument has it's ownership transferred to Qt.

插入 child 项在 index in the list of children.

If the child has already been inserted somewhere else it wont be inserted again.

QTreeWidgetItem.insertChildren ( self , int  index , list-of-QTreeWidgetItem  children )

children argument has it's ownership transferred to Qt.

Inserts the given list of children into the list of the item children at index .

Children that have already been inserted somewhere else wont be inserted.

该函数在 Qt 4.1 引入。

bool QTreeWidgetItem.isDisabled ( self )

Returns true if the item is disabled; otherwise returns false.

该函数在 Qt 4.3 引入。

另请参阅 setFlags ().

bool QTreeWidgetItem.isExpanded ( self )

Returns true if the item is expanded, otherwise returns false.

该函数在 Qt 4.2 引入。

另请参阅 setExpanded ().

bool QTreeWidgetItem.isFirstColumnSpanned ( self )

Returns true if the item is spanning all the columns in a row; otherwise returns false.

该函数在 Qt 4.3 引入。

另请参阅 setFirstColumnSpanned ().

bool QTreeWidgetItem.isHidden ( self )

Returns true if the item is hidden, otherwise returns false.

该函数在 Qt 4.2 引入。

另请参阅 setHidden ().

bool QTreeWidgetItem.isSelected ( self )

Returns true if the item is selected, otherwise returns false.

该函数在 Qt 4.2 引入。

另请参阅 setSelected ().

QTreeWidgetItem QTreeWidgetItem.parent ( self )

返回项的父级。

另请参阅 child ().

QTreeWidgetItem.read ( self , QDataStream   in )

读取项从流 in . This only reads data into a single item.

另请参阅 write ().

QTreeWidgetItem.removeChild ( self , QTreeWidgetItem   child )

child argument

Removes the given item indicated by child . The removed item will not be deleted.

QTreeWidgetItem.setBackground ( self , int  column , QBrush   brush )

设置标签背景笔刷在给定 column 到指定 brush .

该函数在 Qt 4.2 引入。

另请参阅 background () 和 setForeground ().

QTreeWidgetItem.setBackgroundColor ( self , int  column , QColor   color )

QTreeWidgetItem.setCheckState ( self , int  column , Qt.CheckState   state )

设置项在给定 column check state to be state .

另请参阅 checkState ().

QTreeWidgetItem.setChildIndicatorPolicy ( self , ChildIndicatorPolicy   policy )

设置项指示器 policy . This policy decides when the tree branch expand/collapse indicator is shown. The default value is ShowForChildren.

另请参阅 childIndicatorPolicy ().

QTreeWidgetItem.setData ( self , int  column , int  role , QVariant  value )

Sets the value for the item's column and role to the given value .

role describes the type of data specified by value , and is defined by the Qt.ItemDataRole 枚举。

另请参阅 data ().

QTreeWidgetItem.setDisabled ( self , bool  disabled )

禁用项若 disabled is true; otherwise enables the item.

该函数在 Qt 4.3 引入。

另请参阅 isDisabled () 和 setFlags ().

QTreeWidgetItem.setExpanded ( self , bool  aexpand )

展开项若 expand is true, otherwise collapses the item.

警告: QTreeWidgetItem 必须被添加到 QTreeWidget before calling this 函数。

该函数在 Qt 4.2 引入。

另请参阅 isExpanded ().

QTreeWidgetItem.setFirstColumnSpanned ( self , bool  aspan )

把第 1 区间设为跨所有列若 span is true; otherwise all item sections are shown.

该函数在 Qt 4.3 引入。

另请参阅 isFirstColumnSpanned ().

QTreeWidgetItem.setFlags ( self , Qt.ItemFlags   aflags )

将项的标志设为给定 flags . These determine whether the item can be selected or modified. This is often used to disable an item.

另请参阅 flags ().

QTreeWidgetItem.setFont ( self , int  column , QFont   afont )

设置用于显示文本的字体在给定 column 到给定 font .

另请参阅 font (), setText (),和 setForeground ().

QTreeWidgetItem.setForeground ( self , int  column , QBrush   brush )

设置标签的前景笔刷在给定 column 到指定 brush .

该函数在 Qt 4.2 引入。

另请参阅 foreground () 和 setBackground ().

QTreeWidgetItem.setHidden ( self , bool  ahide )

隐藏项若 hide is true, otherwise shows the 项。

该函数在 Qt 4.2 引入。

另请参阅 isHidden ().

QTreeWidgetItem.setIcon ( self , int  column , QIcon   aicon )

设置要显示的图标在给定 column to icon .

另请参阅 icon (), setText (),和 iconSize .

QTreeWidgetItem.setSelected ( self , bool  aselect )

将项的选定状态设为 select .

该函数在 Qt 4.2 引入。

另请参阅 isSelected ().

QTreeWidgetItem.setSizeHint ( self , int  column , QSize   size )

Sets the size hint for the tree item in the given column to be size . If no size hint is set, the item delegate will compute the size hint based on the item data.

该函数在 Qt 4.1 引入。

另请参阅 sizeHint ().

QTreeWidgetItem.setStatusTip ( self , int  column , QString  astatusTip )

Sets the status tip for the given column 到给定 statusTip . QTreeWidget mouse tracking needs to be enabled for this feature to work.

另请参阅 statusTip (), setToolTip (),和 setWhatsThis ().

QTreeWidgetItem.setText ( self , int  column , QString  atext )

Sets the text to be displayed in the given column 到 given text .

另请参阅 text (), setFont (),和 setForeground ().

QTreeWidgetItem.setTextAlignment ( self , int  column , int  alignment )

Sets the text alignment for the label in the given column alignment specified (see Qt.AlignmentFlag ).

另请参阅 textAlignment ().

QTreeWidgetItem.setTextColor ( self , int  column , QColor   color )

QTreeWidgetItem.setToolTip ( self , int  column , QString  atoolTip )

设置工具提示为给定 column to toolTip .

另请参阅 toolTip (), setStatusTip (),和 setWhatsThis ().

QTreeWidgetItem.setWhatsThis ( self , int  column , QString  awhatsThis )

设置 What's This? 帮助为给定 column to whatsThis .

另请参阅 whatsThis (), setStatusTip (),和 setToolTip ().

QSize QTreeWidgetItem.sizeHint ( self , int  column )

Returns the size hint set for the tree item in the given column (见 QSize ).

该函数在 Qt 4.1 引入。

另请参阅 setSizeHint ().

QTreeWidgetItem.sortChildren ( self , int  column , Qt.SortOrder   order )

Sorts the children of the item using the given order , by the values in the given column .

注意: This function does nothing if the item is not associated with a QTreeWidget .

该函数在 Qt 4.2 引入。

QString QTreeWidgetItem.statusTip ( self , int  column )

返回状态提示内容为给定 column .

另请参阅 setStatusTip ().

QTreeWidgetItem QTreeWidgetItem.takeChild ( self , int  index )

QTreeWidgetItem result

移除项在 index and returns it, otherwise return 0.

list-of-QTreeWidgetItem QTreeWidgetItem.takeChildren ( self )

list-of-QTreeWidgetItem result

Removes the list of children and returns it, otherwise returns an empty list.

该函数在 Qt 4.1 引入。

QString QTreeWidgetItem.text ( self , int  column )

返回文本在指定 column .

另请参阅 setText ().

int QTreeWidgetItem.textAlignment ( self , int  column )

返回标签的文本对齐方式在给定 column (见 Qt.AlignmentFlag ).

另请参阅 setTextAlignment ().

QColor QTreeWidgetItem.textColor ( self , int  column )

QString QTreeWidgetItem.toolTip ( self , int  column )

返回工具提示为给定 column .

另请参阅 setToolTip ().

QTreeWidget QTreeWidgetItem.treeWidget ( self )

返回包含项的树 Widget。

int QTreeWidgetItem.type ( self )

返回类型被传递给 QTreeWidgetItem 构造函数。

QString QTreeWidgetItem.whatsThis ( self , int  column )

返回 What's This? 帮助内容为给定 column .

另请参阅 setWhatsThis ().

QTreeWidgetItem.write ( self , QDataStream   out )

把项写入流 out . This only writes data from one single item.

另请参阅 read ().

bool QTreeWidgetItem.__ge__ ( self , QTreeWidgetItem   other )

bool QTreeWidgetItem.__lt__ ( self , QTreeWidgetItem   other )