QListWidgetItem Class Reference

[ QtGui module]

QListWidgetItem 类提供项,用于 QListWidget 项视图类。 更多...

类型

方法

Special Methods


详细描述

QListWidgetItem 类提供项,用于 QListWidget 项视图类。

QListWidgetItem 表示单项,在 QListWidget . Each item can hold several pieces of information, and will display them appropriately.

The item view convenience classes use a classic item-based interface rather than a pure model/view approach. For a more flexible list view widget, consider using the QListView 类采用标准模型。

List items can be inserted automatically into a list, when they are constructed, by specifying the list widget:

     new QListWidgetItem(tr("Hazel"), listWidget);
			

Alternatively, list items can also be created without a parent widget, and later inserted into a list using QListWidget.insertItem ().

List items are typically used to display text () and an icon (). These are set with the setText () 和 setIcon () functions. The appearance of the text can be customized with setFont (), setForeground (),和 setBackground (). Text in list items can be aligned using the setTextAlignment () function. Tooltips, status tips and "What's This?" help can be added to list items with setToolTip (), setStatusTip (),和 setWhatsThis ().

By default, items are enabled, selectable, checkable, and can be the source of drag and drop operations.

Each item's flags can be changed by calling setFlags () with the appropriate 值 (见 Qt.ItemFlags ). Checkable items can be checked, unchecked and partially checked 采用 setCheckState () 函数。 The corresponding checkState () function indicates the item's current check state.

isHidden () function can be used to determine whether the item is hidden. To hide an item, use setHidden ().

子类化

When subclassing QListWidgetItem to provide custom items, it is possible to define new types for them enabling them to be distinguished from standard items. For subclasses that require this feature, ensure that you call the base class constructor with a new type value equal to or greater than UserType , within your 构造函数。


类型文档编制

QListWidgetItem.ItemType

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

常量 描述
QListWidgetItem.Type 0 The default type for list widget items.
QListWidgetItem.UserType 1000 The minimum value for custom types. Values below UserType are reserved by Qt.

可以定义新用户类型在 QListWidgetItem subclasses to ensure that custom items are treated specially.

另请参阅 type ().


方法文档编制

QListWidgetItem.__init__ ( self , QListWidget   parent  = None, int  type  = QListWidgetItem.Type)

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

Constructs an empty list widget item of the specified type with the given parent 。若 parent 不是 specified, the item will need to be inserted into a list widget with QListWidget.insertItem ().

This constructor inserts the item into the model of the parent that is passed to the constructor. If the model is sorted then the behavior of the insert is undetermined since the model will call the '<' operator method on the item which, at this point, is not yet constructed. To avoid the undetermined behavior, we recommend not to specify the parent and use QListWidget.insertItem () 代替。

另请参阅 type ().

QListWidgetItem.__init__ ( self , QString  text , QListWidget   parent  = None, int  type  = QListWidgetItem.Type)

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

Constructs an empty list widget item of the specified type with the given text and parent 。若 parent is not specified, the item will need to be inserted into a list widget with QListWidget.insertItem ().

This constructor inserts the item into the model of the parent that is passed to the constructor. If the model is sorted then the behavior of the insert is undetermined since the model will call the '<' operator method on the item which, at this point, is not yet constructed. To avoid the undetermined behavior, we recommend not to specify the parent and use QListWidget.insertItem () 代替。

另请参阅 type ().

QListWidgetItem.__init__ ( self , QIcon   icon , QString  text , QListWidget   parent  = None, int  type  = QListWidgetItem.Type)

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

Constructs an empty list widget item of the specified type with the given icon , text and parent . If the parent is not specified, the item will need to be inserted into a list widget with QListWidget.insertItem ().

This constructor inserts the item into the model of the parent that is passed to the constructor. If the model is sorted then the behavior of the insert is undetermined since the model will call the '<' operator method on the item which, at this point, is not yet constructed. To avoid the undetermined behavior, we recommend not to specify the parent and use QListWidget.insertItem () 代替。

另请参阅 type ().

QListWidgetItem.__init__ ( self , QListWidgetItem   other )

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

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

该函数在 Qt 4.1 引入。

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

QBrush QListWidgetItem.background ( self )

Returns the brush used to display the list item's background.

该函数在 Qt 4.2 引入。

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

QColor QListWidgetItem.backgroundColor ( self )

Qt.CheckState QListWidgetItem.checkState ( self )

Returns the checked state of the list item (see Qt.CheckState ).

另请参阅 setCheckState () 和 flags ().

QListWidgetItem QListWidgetItem.clone ( self )

Creates an exact copy of the item.

QVariant QListWidgetItem.data ( self , int  role )

Returns the item's data for a given role . Reimplement this function if you need extra roles or special behavior for certain roles.

另请参阅 Qt.ItemDataRole and setData ().

Qt.ItemFlags QListWidgetItem.flags ( self )

Returns the item flags for this item (see Qt.ItemFlags ).

另请参阅 setFlags ().

QFont QListWidgetItem.font ( self )

Returns the font used to display this list item's text.

另请参阅 setFont ().

QBrush QListWidgetItem.foreground ( self )

Returns the brush used to display the list item's foreground (e.g. text).

该函数在 Qt 4.2 引入。

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

QIcon QListWidgetItem.icon ( self )

Returns the list item's icon.

另请参阅 setIcon () 和 iconSize .

bool QListWidgetItem.isHidden ( self )

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

该函数在 Qt 4.2 引入。

另请参阅 setHidden ().

bool QListWidgetItem.isSelected ( self )

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

该函数在 Qt 4.2 引入。

另请参阅 setSelected ().

QListWidget QListWidgetItem.listWidget ( self )

Returns the list widget containing the item.

QListWidgetItem.read ( self , QDataStream   in )

读取项从流 in .

另请参阅 write ().

QListWidgetItem.setBackground ( self , QBrush   brush )

Sets the background brush of the list item to the given brush .

该函数在 Qt 4.2 引入。

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

QListWidgetItem.setBackgroundColor ( self , QColor   color )

QListWidgetItem.setCheckState ( self , Qt.CheckState   state )

Sets the check state of the list item to state .

另请参阅 checkState ().

QListWidgetItem.setData ( self , int  role , QVariant  value )

Sets the data for a given role 到给定 value . Reimplement this function if you need extra roles or special behavior for certain roles.

另请参阅 Qt.ItemDataRole and data ().

QListWidgetItem.setFlags ( self , Qt.ItemFlags   aflags )

Sets the item flags for the list item to flags .

另请参阅 flags () and Qt.ItemFlags .

QListWidgetItem.setFont ( self , QFont   afont )

Sets the font used when painting the item to the given font .

另请参阅 font ().

QListWidgetItem.setForeground ( self , QBrush   brush )

Sets the foreground brush of the list item to the given brush .

该函数在 Qt 4.2 引入。

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

QListWidgetItem.setHidden ( self , bool  ahide )

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

该函数在 Qt 4.2 引入。

另请参阅 isHidden ().

QListWidgetItem.setIcon ( self , QIcon   aicon )

Sets the icon for the list item to the given icon .

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

QListWidgetItem.setSelected ( self , bool  aselect )

将项的选定状态设为 select .

该函数在 Qt 4.2 引入。

另请参阅 isSelected ().

QListWidgetItem.setSizeHint ( self , QSize   size )

Sets the size hint for the list item 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 ().

QListWidgetItem.setStatusTip ( self , QString  astatusTip )

Sets the status tip for the list item to the text specified by statusTip . QListWidget mouseTracking needs to be enabled for this feature to work.

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

QListWidgetItem.setText ( self , QString  atext )

把列表 Widget 项的文本,设为给定 text .

另请参阅 text ().

QListWidgetItem.setTextAlignment ( self , int  alignment )

把列表项的文本对齐方式,设为 alignment .

另请参阅 textAlignment () 和 Qt.AlignmentFlag .

QListWidgetItem.setTextColor ( self , QColor   color )

QListWidgetItem.setToolTip ( self , QString  atoolTip )

Sets the tooltip for the list item to the text specified by toolTip .

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

QListWidgetItem.setWhatsThis ( self , QString  awhatsThis )

Sets the "What's This?" help for the list item to the text 指定通过 whatsThis .

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

QSize QListWidgetItem.sizeHint ( self )

返回列表项的大小提示设置。

该函数在 Qt 4.1 引入。

另请参阅 setSizeHint ().

QString QListWidgetItem.statusTip ( self )

返回列表项的状态提示。

另请参阅 setStatusTip ().

QString QListWidgetItem.text ( self )

返回列表项的文本。

另请参阅 setText ().

int QListWidgetItem.textAlignment ( self )

返回列表项的文本对齐方式。

另请参阅 setTextAlignment () 和 Qt.AlignmentFlag .

QColor QListWidgetItem.textColor ( self )

QString QListWidgetItem.toolTip ( self )

返回列表项的工具提示。

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

int QListWidgetItem.type ( self )

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

QString QListWidgetItem.whatsThis ( self )

返回列表项的 What's This? 帮助文本。

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

QListWidgetItem.write ( self , QDataStream   out )

把项写入流 out .

另请参阅 read ().

bool QListWidgetItem.__ge__ ( self , QListWidgetItem   other )

bool QListWidgetItem.__lt__ ( self , QListWidgetItem   other )