PySide6.QtWidgets.QListWidgetItem¶
- class QListWidgetItem¶
- The - QListWidgetItemclass provides an item for use with the- QListWidgetitem view class. More…- Synopsis¶- Methods¶- def - __init__()
- def - background()
- def - checkState()
- def - flags()
- def - font()
- def - foreground()
- def - icon()
- def - isHidden()
- def - isSelected()
- def - listWidget()
- def - setBackground()
- def - setCheckState()
- def - setFlags()
- def - setFont()
- def - setForeground()
- def - setHidden()
- def - setIcon()
- def - setSelected()
- def - setSizeHint()
- def - setStatusTip()
- def - setText()
- def - setToolTip()
- def - setWhatsThis()
- def - sizeHint()
- def - statusTip()
- def - text()
- def - textAlignment()
- def - toolTip()
- def - type()
- def - whatsThis()
 - Virtual methods¶- Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - A - QListWidgetItemrepresents 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 - QListViewclass with a standard model.- 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 - insertItem().- List items are typically used to display - text()and an- icon(). These are set with the- setText()and- setIcon()functions. The appearance of the text can be customized with- setFont(),- setForeground(), and- 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(), and- 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 Qt::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.- The - isHidden()function can be used to determine whether the item is hidden. To hide an item, use- setHidden().- Subclassing¶- When subclassing - QListWidgetItemto 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 constructor.- class ItemType¶
- (inherits - enum.IntEnum) This enum describes the types that are used to describe list widget items.- Constant - Description - QListWidgetItem.Type - The default type for list widget items. - QListWidgetItem.UserType - The minimum value for custom types. Values below UserType are reserved by Qt. - You can define new user types in - QListWidgetItemsubclasses to ensure that custom items are treated specially.- See also 
 - __init__(other)¶
- Parameters:
- other – - QListWidgetItem
 
 - Constructs a copy of - other. Note that- type()and- listWidget()are not copied.- This function is useful when reimplementing - clone().- __init__([listview=None[, type=list()]])
- Parameters:
- listview – - QListWidget
- type – int 
 
 
 - Constructs an empty list widget item of the specified - typewith the given- parent. If- parentis 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()instead.- See also - __init__(text[, listview=None[, type=list()]])
- Parameters:
- text – str 
- listview – - QListWidget
- type – int 
 
 
 - Constructs an empty list widget item of the specified - typewith the given- textand- 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()instead.- See also - __init__(icon, text[, listview=None[, type=list()]])
- Parameters:
- icon – - QIcon
- text – str 
- listview – - QListWidget
- type – int 
 
 
 - Constructs an empty list widget item of the specified - typewith the given- icon,- textand- 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()instead.- See also - Returns the brush used to display the list item’s background. - See also - checkState()¶
- Return type:
 
 - Returns the checked state of the list item (see Qt::CheckState). - See also - clone()¶
- Return type:
 
 - Creates an exact copy of the item. - data(role)¶
- Parameters:
- role – int 
- Return type:
- object 
 
 - Returns the item’s data for a given - role. Reimplement this function if you need extra roles or special behavior for certain roles.- See also - Returns the item flags for this item (see Qt::ItemFlags). - See also - Returns the font used to display this list item’s text. - See also - Returns the brush used to display the list item’s foreground (e.g. text). - See also - Returns the list item’s icon. - isHidden()¶
- Return type:
- bool 
 
 - Returns - trueif the item is hidden; otherwise returns- false.- See also - isSelected()¶
- Return type:
- bool 
 
 - Returns - trueif the item is selected; otherwise returns- false.- See also - listWidget()¶
- Return type:
 
 - Returns the list widget containing the item. - __lt__(other)¶
- Parameters:
- other – - QListWidgetItem
- Return type:
- bool 
 
 - Returns - trueif this item’s text is less then- otheritem’s text; otherwise returns- false.- read(in)¶
- Parameters:
- in – - QDataStream
 
 - Reads the item from stream - in.- See also - Sets the background brush of the list item to the given - brush. Setting a default-constructed brush will let the view use the default color from the style.- See also - setCheckState(state)¶
- Parameters:
- state – - CheckState
 
 - Sets the check state of the list item to - state.- See also - setData(role, value)¶
- Parameters:
- role – int 
- value – object 
 
 
 - Sets the data for a given - roleto the given- value. Reimplement this function if you need extra roles or special behavior for certain roles.- Note - The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data. - See also - Sets the item flags for the list item to - flags.- See also - flags()- ItemFlags- Sets the font used when painting the item to the given - font.- See also - Sets the foreground brush of the list item to the given - brush. Setting a default-constructed brush will let the view use the default color from the style.- See also - setHidden(hide)¶
- Parameters:
- hide – bool 
 
 - Hides the item if - hideis true; otherwise shows the item.- See also - Sets the icon for the list item to the given - icon.- setSelected(select)¶
- Parameters:
- select – bool 
 
 - Sets the selected state of the item to - select.- See also - Sets the size hint for the list item to be - size. If no size hint is set or- sizeis invalid, the item delegate will compute the size hint based on the item data.- See also - setStatusTip(statusTip)¶
- Parameters:
- statusTip – str 
 
 - Sets the status tip for the list item to the text specified by - statusTip.- QListWidgetmouseTracking needs to be enabled for this feature to work.- setText(text)¶
- Parameters:
- text – str 
 
 - Sets the text for the list widget item’s to the given - text.- See also - setTextAlignment(alignment)¶
- Parameters:
- alignment – Combination of - AlignmentFlag
 
 - Sets the list item’s text alignment to - alignment.- See also - setTextAlignment(alignment)
- Parameters:
- alignment – - AlignmentFlag
 
 - setTextAlignment(alignment)
- Parameters:
- alignment – int 
 - Note - This function is deprecated. 
 - Use the overload that takes a Qt::Alignment argument. - Sets the list item’s text alignment to - alignment.- See also - Alignment- setToolTip(toolTip)¶
- Parameters:
- toolTip – str 
 
 - Sets the tooltip for the list item to the text specified by - toolTip.- See also - setWhatsThis(whatsThis)¶
- Parameters:
- whatsThis – str 
 
 - Sets the “What’s This?” help for the list item to the text specified by - whatsThis.- See also - Returns the size hint set for the list item. - See also - statusTip()¶
- Return type:
- str 
 
 - Returns the list item’s status tip. - See also - text()¶
- Return type:
- str 
 
 - Returns the list item’s text. - See also - textAlignment()¶
- Return type:
- int 
 
 - Returns the text alignment for the list item. - Note - This function returns an int for historical reasons. It will be corrected to return Qt::Alignment in Qt 7. - See also - setTextAlignment()- Alignment- toolTip()¶
- Return type:
- str 
 
 - Returns the list item’s tooltip. - See also - type()¶
- Return type:
- int 
 
 - Returns the type passed to the - QListWidgetItemconstructor.- whatsThis()¶
- Return type:
- str 
 
 - Returns the list item’s “What’s This?” help text. - See also - write(out)¶
- Parameters:
- out – - QDataStream
 
 - Writes the item to stream - out.- See also