QListWidgetItem¶
The
QListWidgetItem
class provides an item for use with theQListWidget
item view class. More…
Synopsis¶
Functions¶
def
background
()def
backgroundColor
()def
checkState
()def
flags
()def
font
()def
foreground
()def
icon
()def
isHidden
()def
isSelected
()def
listWidget
()def
setBackground
(brush)def
setCheckState
(state)def
setFlags
(flags)def
setFont
(font)def
setForeground
(brush)def
setHidden
(hide)def
setIcon
(icon)def
setSelected
(select)def
setSizeHint
(size)def
setStatusTip
(statusTip)def
setText
(text)def
setTextAlignment
(alignment)def
setTextColor
(color)def
setToolTip
(toolTip)def
setWhatsThis
(whatsThis)def
sizeHint
()def
statusTip
()def
text
()def
textAlignment
()def
textColor
()def
toolTip
()def
type
()def
whatsThis
()
Virtual functions¶
Detailed Description¶
A
QListWidgetItem
represents a single item in aQListWidget
. 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
class with a standard model.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()
and anicon()
. These are set with thesetText()
andsetIcon()
functions. The appearance of the text can be customized withsetFont()
,setForeground()
, andsetBackground()
. Text in list items can be aligned using thesetTextAlignment()
function. Tooltips, status tips and “What’s This?” help can be added to list items withsetToolTip()
,setStatusTip()
, andsetWhatsThis()
.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 (seeItemFlags
). Checkable items can be checked, unchecked and partially checked with thesetCheckState()
function. The correspondingcheckState()
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, usesetHidden()
.
Subclassing¶
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 thanUserType
, within your constructor.
- class PySide2.QtWidgets.QListWidgetItem([listview=None[, type=Type]])¶
PySide2.QtWidgets.QListWidgetItem(icon, text[, listview=None[, type=Type]])
PySide2.QtWidgets.QListWidgetItem(other)
PySide2.QtWidgets.QListWidgetItem(text[, listview=None[, type=Type]])
- param listview:
- param type:
int
- param icon:
- param other:
- param text:
str
Constructs an empty list widget item of the specified
type
with the givenparent
. Ifparent
is not specified, the item will need to be inserted into a list widget withinsertItem()
.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 useinsertItem()
instead.See also
Constructs an empty list widget item of the specified
type
with the givenicon
,text
andparent
. If the parent is not specified, the item will need to be inserted into a list widget withinsertItem()
.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 useinsertItem()
instead.See also
Constructs a copy of
other
. Note thattype()
andlistWidget()
are not copied.This function is useful when reimplementing
clone()
.Constructs an empty list widget item of the specified
type
with the giventext
andparent
. If the parent is not specified, the item will need to be inserted into a list widget withinsertItem()
.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 useinsertItem()
instead.See also
- PySide2.QtWidgets.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 are reserved by Qt.
You can define new user types in
QListWidgetItem
subclasses to ensure that custom items are treated specially.See also
- PySide2.QtWidgets.QListWidgetItem.background()¶
- Return type:
Returns the brush used to display the list item’s background.
See also
- PySide2.QtWidgets.QListWidgetItem.backgroundColor()¶
- Return type:
Note
This function is deprecated.
This function is deprecated. Use
background()
instead.See also
- PySide2.QtWidgets.QListWidgetItem.checkState()¶
- Return type:
Returns the checked state of the list item (see
CheckState
).See also
- PySide2.QtWidgets.QListWidgetItem.clone()¶
- Return type:
Creates an exact copy of the item.
- PySide2.QtWidgets.QListWidgetItem.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
ItemDataRole
setData()
- PySide2.QtWidgets.QListWidgetItem.flags()¶
- Return type:
ItemFlags
Returns the item flags for this item (see
ItemFlags
).See also
- PySide2.QtWidgets.QListWidgetItem.font()¶
- Return type:
Returns the font used to display this list item’s text.
See also
- PySide2.QtWidgets.QListWidgetItem.foreground()¶
- Return type:
Returns the brush used to display the list item’s foreground (e.g. text).
See also
- PySide2.QtWidgets.QListWidgetItem.icon()¶
- Return type:
Returns the list item’s icon.
- PySide2.QtWidgets.QListWidgetItem.isHidden()¶
- Return type:
bool
Returns
true
if the item is hidden; otherwise returnsfalse
.See also
- PySide2.QtWidgets.QListWidgetItem.isSelected()¶
- Return type:
bool
Returns
true
if the item is selected; otherwise returnsfalse
.See also
- PySide2.QtWidgets.QListWidgetItem.listWidget()¶
- Return type:
Returns the list widget containing the item.
- PySide2.QtWidgets.QListWidgetItem.__lt__(other)¶
- Parameters:
- Return type:
bool
- PySide2.QtWidgets.QListWidgetItem.read(in)¶
- Parameters:
Reads the item from stream
in
.See also
- PySide2.QtWidgets.QListWidgetItem.setBackground(brush)¶
- Parameters:
brush –
PySide2.QtGui.QBrush
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
- PySide2.QtWidgets.QListWidgetItem.setBackgroundColor(color)¶
- Parameters:
color –
PySide2.QtGui.QColor
Note
This function is deprecated.
This function is deprecated. Use
setBackground()
instead.See also
- PySide2.QtWidgets.QListWidgetItem.setCheckState(state)¶
- Parameters:
state –
CheckState
Sets the check state of the list item to
state
.See also
- PySide2.QtWidgets.QListWidgetItem.setData(role, value)¶
- Parameters:
role – int
value – object
Sets the data for a given
role
to the givenvalue
. Reimplement this function if you need extra roles or special behavior for certain roles.Note
The default implementation treats
EditRole
andDisplayRole
as referring to the same data.See also
ItemDataRole
data()
- PySide2.QtWidgets.QListWidgetItem.setFlags(flags)¶
- Parameters:
flags –
ItemFlags
Sets the item flags for the list item to
flags
.See also
flags()
ItemFlags
- PySide2.QtWidgets.QListWidgetItem.setFont(font)¶
- Parameters:
font –
PySide2.QtGui.QFont
Sets the font used when painting the item to the given
font
.See also
- PySide2.QtWidgets.QListWidgetItem.setForeground(brush)¶
- Parameters:
brush –
PySide2.QtGui.QBrush
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
- PySide2.QtWidgets.QListWidgetItem.setHidden(hide)¶
- Parameters:
hide – bool
Hides the item if
hide
is true; otherwise shows the item.See also
- PySide2.QtWidgets.QListWidgetItem.setIcon(icon)¶
- Parameters:
icon –
PySide2.QtGui.QIcon
Sets the icon for the list item to the given
icon
.
- PySide2.QtWidgets.QListWidgetItem.setSelected(select)¶
- Parameters:
select – bool
Sets the selected state of the item to
select
.See also
- PySide2.QtWidgets.QListWidgetItem.setSizeHint(size)¶
- Parameters:
size –
PySide2.QtCore.QSize
Sets the size hint for the list item to be
size
. If no size hint is set orsize
is invalid, the item delegate will compute the size hint based on the item data.See also
- PySide2.QtWidgets.QListWidgetItem.setStatusTip(statusTip)¶
- Parameters:
statusTip – str
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)¶
- Parameters:
text – str
Sets the text for the list widget item’s to the given
text
.See also
- PySide2.QtWidgets.QListWidgetItem.setTextAlignment(alignment)¶
- Parameters:
alignment – int
Sets the list item’s text alignment to
alignment
.See also
textAlignment()
AlignmentFlag
- PySide2.QtWidgets.QListWidgetItem.setTextColor(color)¶
- Parameters:
color –
PySide2.QtGui.QColor
Note
This function is deprecated.
This function is deprecated. Use
setForeground()
instead.See also
- PySide2.QtWidgets.QListWidgetItem.setToolTip(toolTip)¶
- Parameters:
toolTip – str
Sets the tooltip for the list item to the text specified by
toolTip
.See also
- PySide2.QtWidgets.QListWidgetItem.setWhatsThis(whatsThis)¶
- Parameters:
whatsThis – str
Sets the “What’s This?” help for the list item to the text specified by
whatsThis
.See also
- PySide2.QtWidgets.QListWidgetItem.sizeHint()¶
- Return type:
Returns the size hint set for the list item.
See also
- PySide2.QtWidgets.QListWidgetItem.statusTip()¶
- Return type:
str
Returns the list item’s status tip.
See also
- PySide2.QtWidgets.QListWidgetItem.text()¶
- Return type:
str
Returns the list item’s text.
See also
- PySide2.QtWidgets.QListWidgetItem.textAlignment()¶
- Return type:
int
Returns the text alignment for the list item.
See also
setTextAlignment()
AlignmentFlag
- PySide2.QtWidgets.QListWidgetItem.textColor()¶
- Return type:
Note
This function is deprecated.
Returns the color used to display the list item’s text.
This function is deprecated. Use
foreground()
instead.See also
- PySide2.QtWidgets.QListWidgetItem.toolTip()¶
- Return type:
str
Returns the list item’s tooltip.
See also
- PySide2.QtWidgets.QListWidgetItem.type()¶
- Return type:
int
Returns the type passed to the
QListWidgetItem
constructor.
- PySide2.QtWidgets.QListWidgetItem.whatsThis()¶
- Return type:
str
Returns the list item’s “What’s This?” help text.
See also
- PySide2.QtWidgets.QListWidgetItem.write(out)¶
- Parameters:
Writes the item to stream
out
.See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.