CopperSpice API  1.9.1
QListWidgetItem Class Reference

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

Public Types

enum  ItemType
 

Public Methods

 QListWidgetItem (const QIcon &icon, const QString &text, QListWidget *view=nullptr, int type=Type)
 
 QListWidgetItem (const QListWidgetItem &other)
 
 QListWidgetItem (const QString &text, QListWidget *view=nullptr, int type=Type)
 
 QListWidgetItem (QListWidget *view=nullptr, int type=Type)
 
virtual ~QListWidgetItem ()
 
QBrush background () const
 
QColor backgroundColor () const
 
Qt::CheckState checkState () const
 
virtual QListWidgetItem * clone () const
 
virtual QVariant data (int role) const
 
Qt::ItemFlags flags () const
 
QFont font () const
 
QBrush foreground () const
 
QIcon icon () const
 
bool isHidden () const
 
bool isSelected () const
 
QListWidgetlistWidget () const
 
virtual bool operator< (const QListWidgetItem &other) const
 
QListWidgetItem & operator= (const QListWidgetItem &other)
 
virtual void read (QDataStream &in)
 
void setBackground (const QBrush &brush)
 
virtual void setBackgroundColor (const QColor &color)
 
void setCheckState (Qt::CheckState state)
 
virtual void setData (int role, const QVariant &value)
 
void setFlags (Qt::ItemFlags flags)
 
void setFont (const QFont &font)
 
void setForeground (const QBrush &brush)
 
void setHidden (bool hide)
 
void setIcon (const QIcon &icon)
 
void setSelected (bool select)
 
void setSizeHint (const QSize &size)
 
void setStatusTip (const QString &statusTip)
 
void setText (const QString &text)
 
void setTextAlignment (int alignment)
 
void setTextColor (const QColor &color)
 
void setToolTip (const QString &toolTip)
 
void setWhatsThis (const QString &whatsThis)
 
QSize sizeHint () const
 
QString statusTip () const
 
QString text () const
 
int textAlignment () const
 
QColor textColor () const
 
QString toolTip () const
 
int type () const
 
QString whatsThis () const
 
virtual void write (QDataStream &out) const
 

Friends

class QListWidget
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &stream, const QListWidgetItem &item)
 
QDataStreamoperator>> (QDataStream &stream, QListWidgetItem &item)
 

Detailed Description

The QListWidgetItem class provides an item for use with the QListWidget item view class. This class represents a single item in a QListWidget. Each item can hold several pieces of information, and will display them appropriately. The item view 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 QListWidget::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 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.

See also
QListWidget, QTreeWidgetItem, QTableWidgetItem, Model/View Architecture

Member Enumeration Documentation

This enum describes the types that are used to describe list widget items.

ConstantValueDescription
QListWidgetItem::Type0The default type for list widget items.
QListWidgetItem::UserType1000The minimum value for custom types. Values below UserType are reserved for CopperSpice.

You can define new user types in QListWidgetItem subclasses to ensure that custom items are treated specially.

See also
type()

Constructor & Destructor Documentation

QListWidgetItem::QListWidgetItem ( QListWidget view = nullptr,
int  type = Type 
)
explicit

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

See also
type()
QListWidgetItem::QListWidgetItem ( const QString text,
QListWidget view = nullptr,
int  type = Type 
)
explicit

Constructs an empty list widget item of the specified type with the given text and view. If the view 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.

See also
type()
QListWidgetItem::QListWidgetItem ( const QIcon icon,
const QString text,
QListWidget view = nullptr,
int  type = Type 
)
explicit

Constructs an empty list widget item of the specified type with the given icon, text and view. If the view 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.

See also
type()
QListWidgetItem::QListWidgetItem ( const QListWidgetItem &  other)

Constructs a copy of other. Note that type() and listWidget() are not copied. This method is useful when reimplementing clone().

See also
data(), flags()
QListWidgetItem::~QListWidgetItem ( )
virtual

Destroys the list item.

Method Documentation

QBrush QListWidgetItem::background ( ) const
inline

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

See also
setBackground(), foreground()
QColor QListWidgetItem::backgroundColor ( ) const
inlinedeprecated
Deprecated:
This method is deprecated. Use background() instead.
See also
setBackgroundColor()
Qt::CheckState QListWidgetItem::checkState ( ) const
inline

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

See also
setCheckState(), flags()
QListWidgetItem * QListWidgetItem::clone ( ) const
virtual

Creates an exact copy of the item.

QVariant QListWidgetItem::data ( int  role) const
virtual

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
setData(), Qt::ItemDataRole
Qt::ItemFlags QListWidgetItem::flags ( ) const
inline

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

See also
setFlags()
QFont QListWidgetItem::font ( ) const
inline

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

See also
setFont()
QBrush QListWidgetItem::foreground ( ) const
inline

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

See also
setForeground(), background()
QIcon QListWidgetItem::icon ( ) const
inline

Returns the list item's icon.

See also
setIcon(), QAbstractItemView::iconSize
bool QListWidgetItem::isHidden ( ) const
inline

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

See also
setHidden()
bool QListWidgetItem::isSelected ( ) const
inline

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

See also
setSelected()
QListWidget * QListWidgetItem::listWidget ( ) const
inline

Returns the list widget containing the item.

bool QListWidgetItem::operator< ( const QListWidgetItem &  other) const
virtual

Returns true if this item's text is less then other item's text, otherwise returns false.

QListWidgetItem & QListWidgetItem::operator= ( const QListWidgetItem &  other)

Copy assigns from other and returns a reference to this object. The value for type() and listWidget() are not copied.

void QListWidgetItem::read ( QDataStream in)
virtual

Reads the item from stream in.

See also
write()
void QListWidgetItem::setBackground ( const QBrush brush)
inline

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

See also
background(), setForeground()
void QListWidgetItem::setBackgroundColor ( const QColor color)
inlinedeprecatedvirtual
Deprecated:
This method is deprecated. Use setBackground() instead.
See also
backgroundColor()
void QListWidgetItem::setCheckState ( Qt::CheckState  state)
inline

Sets the check state of the list item to state.

See also
checkState()
void QListWidgetItem::setData ( int  role,
const QVariant value 
)
virtual

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
data(), Qt::ItemDataRole
void QListWidgetItem::setFlags ( Qt::ItemFlags  flags)

Sets the item flags for the list item to flags.

See also
flags(), Qt::ItemFlags
void QListWidgetItem::setFont ( const QFont font)
inline

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

See also
font()
void QListWidgetItem::setForeground ( const QBrush brush)
inline

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

See also
foreground(), setBackground()
void QListWidgetItem::setHidden ( bool  hide)
inline

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

See also
isHidden()
void QListWidgetItem::setIcon ( const QIcon icon)
inline

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

See also
icon(), text(), QAbstractItemView::iconSize
void QListWidgetItem::setSelected ( bool  select)
inline

Sets the selected state of the item to select.

See also
isSelected()
void QListWidgetItem::setSizeHint ( const QSize size)
inline

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.

See also
sizeHint()
void QListWidgetItem::setStatusTip ( const QString statusTip)
inline

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.

See also
statusTip(), setToolTip(), setWhatsThis(), QWidget::setMouseTracking()
void QListWidgetItem::setText ( const QString text)
inline

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

See also
text()
void QListWidgetItem::setTextAlignment ( int  alignment)
inline

Sets the list item's text alignment to alignment.

See also
textAlignment(), Qt::AlignmentFlag
void QListWidgetItem::setTextColor ( const QColor color)
inlinedeprecated
Deprecated:
This method is deprecated. Use setForeground() instead.
See also
textColor()
void QListWidgetItem::setToolTip ( const QString toolTip)
inline

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

See also
toolTip(), setStatusTip(), setWhatsThis()
void QListWidgetItem::setWhatsThis ( const QString whatsThis)
inline

Sets the "What's This?" help for the list item to the text specified by whatsThis.

See also
whatsThis(), setStatusTip(), setToolTip()
QSize QListWidgetItem::sizeHint ( ) const
inline

Returns the size hint set for the list item.

See also
setSizeHint()
QString QListWidgetItem::statusTip ( ) const
inline

Returns the list item's status tip.

See also
setStatusTip()
QString QListWidgetItem::text ( ) const
inline

Returns the list item's text.

See also
setText()
int QListWidgetItem::textAlignment ( ) const
inline

Returns the text alignment for the list item.

See also
setTextAlignment(), Qt::AlignmentFlag
QColor QListWidgetItem::textColor ( ) const
inlinedeprecated
Deprecated:
This method is deprecated. Use foreground() instead.

Returns the color used to display the list item's text.

See also
setTextColor()
QString QListWidgetItem::toolTip ( ) const
inline

Returns the list item's tooltip.

See also
setToolTip(), statusTip(), whatsThis()
int QListWidgetItem::type ( ) const
inline

Returns the type passed to the QListWidgetItem constructor.

QString QListWidgetItem::whatsThis ( ) const
inline

Returns the list item's "What's This?" help text.

See also
setWhatsThis(), statusTip(), toolTip()
void QListWidgetItem::write ( QDataStream out) const
virtual

Writes the item to stream out.

See also
read()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QListWidgetItem &  item 
)
related

Writes item to the stream and returns a reference to the stream. This operator uses QListWidgetItem::write().

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream stream,
QListWidgetItem &  item 
)
related

Reads from the stream into item and returns a reference to the stream. This operator uses QListWidgetItem::read().

Refer to Serializing Data Types for additional information.