QListWidgetItem 类提供项,用于 QListWidget 项视图类。 更多...
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 构造函数。
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 ().
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 ().
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 ().
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 ().
构造副本为 other 。注意 type () 和 listWidget () are not copied.
此函数是有用的,当重实现 clone ().
该函数在 Qt 4.1 引入。
Returns the brush used to display the list item's background.
该函数在 Qt 4.2 引入。
另请参阅 setBackground () 和 foreground ().
Returns the checked state of the list item (see Qt.CheckState ).
另请参阅 setCheckState () 和 flags ().
Creates an exact copy of the item.
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 ().
Returns the item flags for this item (see Qt.ItemFlags ).
另请参阅 setFlags ().
Returns the font used to display this list item's text.
另请参阅 setFont ().
Returns the brush used to display the list item's foreground (e.g. text).
该函数在 Qt 4.2 引入。
另请参阅 setForeground () 和 background ().
Returns the list item's icon.
Returns true if the item is hidden; otherwise returns false.
该函数在 Qt 4.2 引入。
另请参阅 setHidden ().
Returns true if the item is selected; otherwise returns false.
该函数在 Qt 4.2 引入。
另请参阅 setSelected ().
Returns the list widget containing the item.
读取项从流 in .
另请参阅 write ().
Sets the background brush of the list item to the given brush .
该函数在 Qt 4.2 引入。
另请参阅 background () 和 setForeground ().
Sets the check state of the list item to state .
另请参阅 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 and data ().
Sets the item flags for the list item to flags .
另请参阅 flags () and Qt.ItemFlags .
Sets the font used when painting the item to the given font .
另请参阅 font ().
Sets the foreground brush of the list item to the given brush .
该函数在 Qt 4.2 引入。
另请参阅 foreground () 和 setBackground ().
隐藏项若 hide is true; otherwise shows the 项。
该函数在 Qt 4.2 引入。
另请参阅 isHidden ().
Sets the icon for the list item to the given icon .
另请参阅 icon (), text (),和 iconSize .
将项的选定状态设为 select .
该函数在 Qt 4.2 引入。
另请参阅 isSelected ().
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 ().
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 ().
把列表 Widget 项的文本,设为给定 text .
另请参阅 text ().
把列表项的文本对齐方式,设为 alignment .
另请参阅 textAlignment () 和 Qt.AlignmentFlag .
Sets the tooltip for the list item to the text specified by toolTip .
另请参阅 toolTip (), setStatusTip (),和 setWhatsThis ().
Sets the "What's This?" help for the list item to the text 指定通过 whatsThis .
另请参阅 whatsThis (), setStatusTip (),和 setToolTip ().
返回列表项的大小提示设置。
该函数在 Qt 4.1 引入。
另请参阅 setSizeHint ().
返回列表项的状态提示。
另请参阅 setStatusTip ().
返回列表项的文本。
另请参阅 setText ().
返回列表项的文本对齐方式。
另请参阅 setTextAlignment () 和 Qt.AlignmentFlag .
返回列表项的工具提示。
另请参阅 setToolTip (), statusTip (),和 whatsThis ().
返回类型被传递给 QListWidgetItem 构造函数。
返回列表项的 What's This? 帮助文本。
另请参阅 setWhatsThis (), statusTip (),和 toolTip ().
把项写入流 out .
另请参阅 read ().