内容表

上一话题

QListWidget

下一话题

QMainWindow

QListWidgetItem

QListWidgetItem class provides an item for use with the QListWidget 项视图类。 更多

Inheritance diagram of PySide2.QtWidgets.QListWidgetItem

概要

函数

虚函数

详细描述

A QListWidgetItem represents a single item in a 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 insertItem() .

List items are typically used to display text() icon() . These are set with the setText() and 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 value (see ItemFlags ). Checkable items can be checked, unchecked and partially checked with the setCheckState() function. 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() .

子类化

当子类化 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 构造函数。

class QListWidgetItem ( [ listview=None [ , type=Type ] ] )

QListWidgetItem(icon, text[, listview=None[, type=Type]])

QListWidgetItem(other)

QListWidgetItem(text[, listview=None[, type=Type]])

param listview

QListWidget

param type

int

param icon

QIcon

param other

QListWidgetItem

param text

unicode

Constructs an empty list widget item of the specified type 采用给定 parent 。若 parent is not specified, the item will need to be inserted into a list widget with 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 insertItem() 代替。

另请参阅

type()

Constructs an empty list widget item of the specified type 采用给定 icon , text and parent . If the parent is not specified, the item will need to be inserted into a list widget with 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 insertItem() 代替。

另请参阅

type()

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

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

另请参阅

data() flags()

Constructs an empty list widget item of the specified type 采用给定 text and parent . If the parent is not specified, the item will need to be inserted into a list widget with 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 insertItem() 代替。

另请参阅

type()

PySide2.QtWidgets.QListWidgetItem. ItemType

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

常量

描述

QListWidgetItem.Type

The default type for list widget items.

QListWidgetItem.UserType

The minimum value for custom types. Values below are reserved by Qt.

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

另请参阅

type()

PySide2.QtWidgets.QListWidgetItem. background ( )
返回类型

QBrush

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

PySide2.QtWidgets.QListWidgetItem. backgroundColor ( )
返回类型

QColor

注意

此函数被弃用。

This function is deprecated. Use background() 代替。

PySide2.QtWidgets.QListWidgetItem. checkState ( )
返回类型

CheckState

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

PySide2.QtWidgets.QListWidgetItem. clone ( )
返回类型

QListWidgetItem

Creates an exact copy of the item.

PySide2.QtWidgets.QListWidgetItem. data ( role )
参数

role int

返回类型

object

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

另请参阅

ItemDataRole setData()

PySide2.QtWidgets.QListWidgetItem. flags ( )
返回类型

ItemFlags

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

另请参阅

setFlags()

PySide2.QtWidgets.QListWidgetItem. font ( )
返回类型

QFont

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

另请参阅

setFont()

PySide2.QtWidgets.QListWidgetItem. foreground ( )
返回类型

QBrush

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

PySide2.QtWidgets.QListWidgetItem. icon ( )
返回类型

QIcon

Returns the list item’s icon.

PySide2.QtWidgets.QListWidgetItem. isHidden ( )
返回类型

bool

返回 true if the item is hidden; otherwise returns false .

另请参阅

setHidden()

PySide2.QtWidgets.QListWidgetItem. isSelected ( )
返回类型

bool

返回 true if the item is selected; otherwise returns false .

另请参阅

setSelected()

PySide2.QtWidgets.QListWidgetItem. listWidget ( )
返回类型

QListWidget

Returns the list widget containing the item.

PySide2.QtWidgets.QListWidgetItem. __lt__ ( other )
参数

other QListWidgetItem

返回类型

bool

PySide2.QtWidgets.QListWidgetItem. read ( in )
参数

in QDataStream

读取项从流 in .

另请参阅

write()

PySide2.QtWidgets.QListWidgetItem. setBackground ( brush )
参数

brush QBrush

Sets the background brush of the list item to the given brush 。设置默认构造的笔刷将使视图使用来自样式的默认颜色。

PySide2.QtWidgets.QListWidgetItem. setBackgroundColor ( color )
参数

color QColor

注意

此函数被弃用。

This function is deprecated. Use setBackground() 代替。

另请参阅

backgroundColor()

PySide2.QtWidgets.QListWidgetItem. setCheckState ( state )
参数

state CheckState

Sets the check state of the list item to state .

另请参阅

checkState()

PySide2.QtWidgets.QListWidgetItem. setData ( role , value )
参数
  • role int

  • value – object

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

注意

默认实现视 EditRole and DisplayRole 为引用相同数据。

另请参阅

ItemDataRole data()

PySide2.QtWidgets.QListWidgetItem. setFlags ( flags )
参数

flags ItemFlags

Sets the item flags for the list item to flags .

另请参阅

flags() ItemFlags

PySide2.QtWidgets.QListWidgetItem. setFont ( font )
参数

font QFont

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

另请参阅

font()

PySide2.QtWidgets.QListWidgetItem. setForeground ( brush )
参数

brush QBrush

Sets the foreground brush of the list item to the given brush 。设置默认构造的笔刷将使视图使用来自样式的默认颜色。

PySide2.QtWidgets.QListWidgetItem. setHidden ( hide )
参数

hide bool

隐藏项若 hide is true; otherwise shows the item.

另请参阅

isHidden()

PySide2.QtWidgets.QListWidgetItem. setIcon ( icon )
参数

icon QIcon

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

PySide2.QtWidgets.QListWidgetItem. setSelected ( select )
参数

select bool

将项的选定状态设为 select .

另请参阅

isSelected()

PySide2.QtWidgets.QListWidgetItem. setSizeHint ( size )
参数

size QSize

Sets the size hint for the list item to be size 。若没有设置尺寸提示或 size 无效,项委托将基于项数据计算尺寸提示。

另请参阅

sizeHint()

PySide2.QtWidgets.QListWidgetItem. setStatusTip ( statusTip )
参数

statusTip – unicode

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.

PySide2.QtWidgets.QListWidgetItem. setText ( text )
参数

text – unicode

Sets the text for the list widget item’s to the given text .

另请参阅

text()

PySide2.QtWidgets.QListWidgetItem. setTextAlignment ( alignment )
参数

alignment int

Sets the list item’s text alignment to alignment .

另请参阅

textAlignment() AlignmentFlag

PySide2.QtWidgets.QListWidgetItem. setTextColor ( color )
参数

color QColor

注意

此函数被弃用。

This function is deprecated. Use setForeground() 代替。

另请参阅

textColor()

PySide2.QtWidgets.QListWidgetItem. setToolTip ( toolTip )
参数

toolTip – unicode

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

PySide2.QtWidgets.QListWidgetItem. setWhatsThis ( whatsThis )
参数

whatsThis – unicode

Sets the “What’s This?” help for the list item to the text specified by whatsThis .

PySide2.QtWidgets.QListWidgetItem. sizeHint ( )
返回类型

QSize

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

另请参阅

setSizeHint()

PySide2.QtWidgets.QListWidgetItem. statusTip ( )
返回类型

unicode

Returns the list item’s status tip.

另请参阅

setStatusTip()

PySide2.QtWidgets.QListWidgetItem. text ( )
返回类型

unicode

Returns the list item’s text.

另请参阅

setText()

PySide2.QtWidgets.QListWidgetItem. textAlignment ( )
返回类型

int

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

另请参阅

setTextAlignment() AlignmentFlag

PySide2.QtWidgets.QListWidgetItem. textColor ( )
返回类型

QColor

注意

此函数被弃用。

Returns the color used to display the list item’s text.

This function is deprecated. Use foreground() 代替。

另请参阅

setTextColor()

PySide2.QtWidgets.QListWidgetItem. toolTip ( )
返回类型

unicode

Returns the list item’s tooltip.

PySide2.QtWidgets.QListWidgetItem. type ( )
返回类型

int

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

PySide2.QtWidgets.QListWidgetItem. whatsThis ( )
返回类型

unicode

Returns the list item’s “What’s This?” help text.

PySide2.QtWidgets.QListWidgetItem. write ( out )
参数

out QDataStream

把项写入流 out .

另请参阅

read()