QListWidgetItem

Inheritance diagram of QListWidgetItem

Synopsis

Functions

Virtual functions

Detailed Description

The PySide.QtGui.QListWidgetItem class provides an item for use with the PySide.QtGui.QListWidget item view class.

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 class 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 QListWidget.insertItem() .

List items are typically used to display PySide.QtGui.QListWidgetItem.text() and an 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() , and 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() , and 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.

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

Subclassing

When subclassing 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 constructor.

class PySide.QtGui.QListWidgetItem([view=None[, type=Type]])
class PySide.QtGui.QListWidgetItem(icon, text[, view=None[, type=Type]])
class PySide.QtGui.QListWidgetItem(other)
class PySide.QtGui.QListWidgetItem(text[, view=None[, type=Type]])
Parameters:

Constructs an empty list widget item of the specified type with the given parent . If 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() instead.

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() instead.

Constructs a copy of other . Note that PySide.QtGui.QListWidgetItem.type() and PySide.QtGui.QListWidgetItem.listWidget() are not copied.

This function is useful when reimplementing PySide.QtGui.QListWidgetItem.clone() .

Constructs an empty list widget item of the specified type with the given 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() instead.

PySide.QtGui.QListWidgetItem.ItemType

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 PySide.QtGui.QListWidgetItem subclasses to ensure that custom items are treated specially.

PySide.QtGui.QListWidgetItem.background()
Return type:PySide.QtGui.QBrush

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

PySide.QtGui.QListWidgetItem.checkState()
Return type:PySide.QtCore.Qt.CheckState

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

PySide.QtGui.QListWidgetItem.clone()
Return type:PySide.QtGui.QListWidgetItem

Creates an exact copy of the item.

PySide.QtGui.QListWidgetItem.data(role)
Parameters:rolePySide.QtCore.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

Qt.ItemDataRole PySide.QtGui.QListWidgetItem.setData()

PySide.QtGui.QListWidgetItem.flags()
Return type:PySide.QtCore.Qt.ItemFlags

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

PySide.QtGui.QListWidgetItem.font()
Return type:PySide.QtGui.QFont

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

PySide.QtGui.QListWidgetItem.foreground()
Return type:PySide.QtGui.QBrush

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

PySide.QtGui.QListWidgetItem.icon()
Return type:PySide.QtGui.QIcon

Returns the list item’s icon.

PySide.QtGui.QListWidgetItem.isHidden()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QListWidgetItem.isSelected()
Return type:PySide.QtCore.bool

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

PySide.QtGui.QListWidgetItem.listWidget()
Return type:PySide.QtGui.QListWidget

Returns the list widget containing the item.

PySide.QtGui.QListWidgetItem.__lt__(other)
Parameters:otherPySide.QtGui.QListWidgetItem
Return type:PySide.QtCore.bool

Returns true if this item’s text is less then other item’s text; otherwise returns false.

PySide.QtGui.QListWidgetItem.read(in)
Parameters:inPySide.QtCore.QDataStream

Reads the item from stream in .

PySide.QtGui.QListWidgetItem.setBackground(brush)
Parameters:brushPySide.QtGui.QBrush

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

PySide.QtGui.QListWidgetItem.setCheckState(state)
Parameters:statePySide.QtCore.Qt.CheckState
PySide.QtGui.QListWidgetItem.setData(role, value)
Parameters:
  • rolePySide.QtCore.int
  • value – object

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

See also

Qt.ItemDataRole PySide.QtGui.QListWidgetItem.data()

PySide.QtGui.QListWidgetItem.setFlags(flags)
Parameters:flagsPySide.QtCore.Qt.ItemFlags
PySide.QtGui.QListWidgetItem.setFont(font)
Parameters:fontPySide.QtGui.QFont

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

PySide.QtGui.QListWidgetItem.setForeground(brush)
Parameters:brushPySide.QtGui.QBrush

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

PySide.QtGui.QListWidgetItem.setHidden(hide)
Parameters:hidePySide.QtCore.bool

Hides the item if hide is true; otherwise shows the item.

PySide.QtGui.QListWidgetItem.setIcon(icon)
Parameters:iconPySide.QtGui.QIcon

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

PySide.QtGui.QListWidgetItem.setSelected(select)
Parameters:selectPySide.QtCore.bool

Sets the selected state of the item to select .

PySide.QtGui.QListWidgetItem.setSizeHint(size)
Parameters:sizePySide.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.

PySide.QtGui.QListWidgetItem.setStatusTip(statusTip)
Parameters: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.

PySide.QtGui.QListWidgetItem.setText(text)
Parameters:text – unicode

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

PySide.QtGui.QListWidgetItem.setTextAlignment(alignment)
Parameters:alignmentPySide.QtCore.int

Sets the list item’s text alignment to alignment .

PySide.QtGui.QListWidgetItem.setToolTip(toolTip)
Parameters:toolTip – unicode

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

PySide.QtGui.QListWidgetItem.setWhatsThis(whatsThis)
Parameters:whatsThis – unicode

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

PySide.QtGui.QListWidgetItem.sizeHint()
Return type:PySide.QtCore.QSize

Returns the size hint set for the list item.

PySide.QtGui.QListWidgetItem.statusTip()
Return type:unicode

Returns the list item’s status tip.

PySide.QtGui.QListWidgetItem.text()
Return type:unicode

Returns the list item’s text.

PySide.QtGui.QListWidgetItem.textAlignment()
Return type:PySide.QtCore.int

Returns the text alignment for the list item.

PySide.QtGui.QListWidgetItem.toolTip()
Return type:unicode

Returns the list item’s tooltip.

PySide.QtGui.QListWidgetItem.type()
Return type:PySide.QtCore.int

Returns the type passed to the PySide.QtGui.QListWidgetItem constructor.

PySide.QtGui.QListWidgetItem.whatsThis()
Return type:unicode

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

PySide.QtGui.QListWidgetItem.write(out)
Parameters:outPySide.QtCore.QDataStream

Writes the item to stream out .