PySide.QtGui.QListWidgetItem class provides an item for use with the PySide.QtGui.QListWidget 项视图类。
A PySide.QtGui.QListWidgetItem represents a single item in a PySide.QtGui.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 PySide.QtGui.QListView 类采用标准模型。
List items can be inserted automatically into a list, when they are constructed, by specifying the list widget:
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 PySide.QtGui.QListWidgetItem.text() 和 PySide.QtGui.QListWidgetItem.icon() . These are set with the PySide.QtGui.QListWidgetItem.setText() and PySide.QtGui.QListWidgetItem.setIcon() functions. The appearance of the text can be customized with PySide.QtGui.QListWidgetItem.setFont() , PySide.QtGui.QListWidgetItem.setForeground() ,和 PySide.QtGui.QListWidgetItem.setBackground() . Text in list items can be aligned using the PySide.QtGui.QListWidgetItem.setTextAlignment() function. Tooltips, status tips and “What's This?” help can be added to list items with PySide.QtGui.QListWidgetItem.setToolTip() , PySide.QtGui.QListWidgetItem.setStatusTip() ,和 PySide.QtGui.QListWidgetItem.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 PySide.QtGui.QListWidgetItem.setFlags() with the appropriate value (see Qt.ItemFlags ). Checkable items can be checked, unchecked and partially checked with the PySide.QtGui.QListWidgetItem.setCheckState() function. The corresponding PySide.QtGui.QListWidgetItem.checkState() function indicates the item's current check state.
PySide.QtGui.QListWidgetItem.isHidden() function can be used to determine whether the item is hidden. To hide an item, use PySide.QtGui.QListWidgetItem.setHidden() .
当子类化 PySide.QtGui.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 构造函数。
| 参数: |
|
|---|
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 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() 代替。
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 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() 代替。
构造副本为 other 。注意 PySide.QtGui.QListWidgetItem.type() and PySide.QtGui.QListWidgetItem.listWidget() are not copied.
此函数是有用的,当重实现 PySide.QtGui.QListWidgetItem.clone() .
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 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() 代替。
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 UserType are reserved by Qt. |
可以定义新用户类型在 PySide.QtGui.QListWidgetItem subclasses to ensure that custom items are treated specially.
| 返回类型: | PySide.QtGui.QBrush |
|---|
Returns the brush used to display the list item's background.
| 返回类型: | PySide.QtCore.Qt.CheckState |
|---|
Returns the checked state of the list item (see Qt.CheckState ).
| 返回类型: | PySide.QtGui.QListWidgetItem |
|---|
Creates an exact copy of the item.
| 参数: | role – PySide.QtCore.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.
另请参阅
Qt.ItemDataRole PySide.QtGui.QListWidgetItem.setData()
| 返回类型: | PySide.QtCore.Qt.ItemFlags |
|---|
Returns the item flags for this item (see Qt.ItemFlags ).
| 返回类型: | PySide.QtGui.QFont |
|---|
Returns the font used to display this list item's text.
| 返回类型: | PySide.QtGui.QBrush |
|---|
Returns the brush used to display the list item's foreground (e.g. text).
| 返回类型: | PySide.QtGui.QIcon |
|---|
Returns the list item's icon.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the item is hidden; otherwise returns false.
| 返回类型: | PySide.QtCore.bool |
|---|
Returns true if the item is selected; otherwise returns false.
| 返回类型: | PySide.QtGui.QListWidget |
|---|
Returns the list widget containing the item.
| 参数: | other – PySide.QtGui.QListWidgetItem |
|---|---|
| 返回类型: | PySide.QtCore.bool |
Returns true if this item's text is less then other item's text; otherwise returns false.
| 参数: | in – PySide.QtCore.QDataStream |
|---|
读取项从流 in .
| 参数: | brush – PySide.QtGui.QBrush |
|---|
Sets the background brush of the list item to the given brush .
| 参数: | state – PySide.QtCore.Qt.CheckState |
|---|
| 参数: |
|
|---|
Sets the data for a given role 到给定 value . Reimplement this function if you need extra roles or special behavior for certain roles.
另请参阅
Qt.ItemDataRole PySide.QtGui.QListWidgetItem.data()
| 参数: | flags – PySide.QtCore.Qt.ItemFlags |
|---|
| 参数: | font – PySide.QtGui.QFont |
|---|
Sets the font used when painting the item to the given font .
| 参数: | brush – PySide.QtGui.QBrush |
|---|
Sets the foreground brush of the list item to the given brush .
| 参数: | hide – PySide.QtCore.bool |
|---|
隐藏项若 hide is true; otherwise shows the item.
| 参数: | icon – PySide.QtGui.QIcon |
|---|
Sets the icon for the list item to the given icon .
| 参数: | select – PySide.QtCore.bool |
|---|
将项的选定状态设为 select .
| 参数: | size – PySide.QtCore.QSize |
|---|
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.
| 参数: | statusTip – unicode |
|---|
Sets the status tip for the list item to the text specified by statusTip . PySide.QtGui.QListWidget mouseTracking needs to be enabled for this feature to work.
| 参数: | text – unicode |
|---|
把列表 Widget 项的文本,设为给定 text .
| 参数: | alignment – PySide.QtCore.int |
|---|
把列表项的文本对齐方式,设为 alignment .
另请参阅
PySide.QtGui.QListWidgetItem.textAlignment() Qt.AlignmentFlag
| 参数: | toolTip – unicode |
|---|
Sets the tooltip for the list item to the text specified by toolTip .
| 参数: | whatsThis – unicode |
|---|
Sets the “What's This?” help for the list item to the text specified by whatsThis .
| 返回类型: | PySide.QtCore.QSize |
|---|
返回列表项的大小提示设置。
| 返回类型: | unicode |
|---|
返回列表项的状态提示。
| 返回类型: | unicode |
|---|
返回列表项的文本。
| 返回类型: | PySide.QtCore.int |
|---|
返回列表项的文本对齐方式。
另请参阅
PySide.QtGui.QListWidgetItem.setTextAlignment() Qt.AlignmentFlag
| 返回类型: | unicode |
|---|
返回列表项的工具提示。
| 返回类型: | PySide.QtCore.int |
|---|
返回类型被传递给 PySide.QtGui.QListWidgetItem 构造函数。
| 返回类型: | unicode |
|---|
Returns the list item's “What's This?” help text.
| 参数: | out – PySide.QtCore.QDataStream |
|---|
把项写入流 out .