Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QListWidgetItem Class Reference

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

    #include <QListWidgetItem>

- List of all members, including inherited members

### Public Functions

- QListWidgetItem ( QListWidget * parent = 0 )
- QListWidgetItem ( const QString & text, QListWidget * parent = 0 )
- virtual ~QListWidgetItem ()
- QColor backgroundColor () const
- int checked () const
- virtual void clear ()
- virtual QVariant data ( int role ) const
- QAbstractItemModel::ItemFlags flags () const
- QFont font () const
- QIcon icon () const
- QListWidget * listWidget () const
- virtual void setBackgroundColor ( const QColor & color )
- void setChecked ( const bool checked )
- virtual void setData ( int role, const QVariant & value )
- void setFlags ( QAbstractItemModel::ItemFlags flags )
- void setFont ( const QFont & font )
- void setIcon ( const QIcon & icon )
- 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 )
- QString statusTip () const
- QString text () const
- int textAlignment () const
- QColor textColor () const
- QString toolTip () const
- QString whatsThis () const
- virtual bool operator< ( const QListWidgetItem & other ) const

## Detailed Description

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

The QListWidgetItem class provides a list item for use with the QListWidget class. List items provide label information that is displayed in list widgets.

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 automatically inserted into a list when they are constructed by specifying the list widget:

            new QListWidgetItem(tr("Hazel"), listWidget);

They can also be created without a parent widget, and later inserted into a list (see 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(), setTextColor(), and setBackgroundColor(). List items can be aligned using the setAlignment() function. Tooltips, status tips and "What's This?" help can be added to list items with setToolTip(), setStatusTip(), and setWhatsThis().

Items can be made checkable by calling setFlags() with the appropriate value (see QAbstractItemModel::ItemFlags). Checkable items can be checked and unchecked with the setChecked() function. The corresponding checked() function indicates whether the item is currently checked.

The isItemHidden() function can be used to determine whether the item is hidden. Items can be hidden with setItemHidden().

See also QListWidgetItem and Model/View Programming.

## Member Function Documentation

### QListWidgetItem::QListWidgetItem ( QListWidget * parent = 0 )

Constructs an empty list widget item with the given parent. If the parent is not specified, the item will need to be inserted into a list widget with QListWidget::insertItem().

### QListWidgetItem::QListWidgetItem ( const QString & text, QListWidget * parent = 0 )

Constructs an empty list widget item 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().

### QListWidgetItem::~QListWidgetItem () `[virtual]`

Destroys the list item.

### QColor QListWidgetItem::backgroundColor () const

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

See also setBackgroundColor() and textColor().

### int QListWidgetItem::checked () const

Returns the checked state of the list item (see QCheckBox::ToggleState).

Only checkable items can be checked. By default, items are not checkable.

See also flags().

### void QListWidgetItem::clear () `[virtual]`

Removes all list items.

### QVariant QListWidgetItem::data ( int role ) const `[virtual]`

This function returns the item's data for a given role (see {QAbstractItemModel::Role}). Reimplement this function if you need extra roles or special behavior for certain roles.

### QAbstractItemModel::ItemFlags QListWidgetItem::flags () const

Returns the item flags for this item (see {QAbstractItemModel::ItemFlags}).

### QFont QListWidgetItem::font () const

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

### QIcon QListWidgetItem::icon () const

Returns the list item's icon.

See also setIcon().

### QListWidget * QListWidgetItem::listWidget () const

Returns the list widget that contains the item.

### void QListWidgetItem::setBackgroundColor ( const QColor & color ) `[virtual]`

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

See also backgroundColor() and setTextColor().

### void QListWidgetItem::setChecked ( const bool checked )

Checks the list item if checked is true; otherwise the list item will be shown as unchecked.

See also checked().

### void QListWidgetItem::setData ( int role, const QVariant & value ) `[virtual]`

This function sets the data for a given role to the given value (see QAbstractItemModel::Role). Reimplement this function if you need extra roles or special behavior for certain roles.

### void QListWidgetItem::setFlags ( QAbstractItemModel::ItemFlags flags )

Sets the item flags for the list item to flags (see QAbstractItemModel::ItemFlags).

### void QListWidgetItem::setFont ( const QFont & font )

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

### void QListWidgetItem::setIcon ( const QIcon & icon )

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

See also icon().

### void QListWidgetItem::setStatusTip ( const QString & statusTip )

Sets the status tip for the list item to the text specified by statusTip.

See also statusTip(), setToolTip(), and setWhatsThis().

### void QListWidgetItem::setText ( const QString & text )

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

See also text().

### void QListWidgetItem::setTextAlignment ( int alignment )

Sets the list item's text alignment to alignment (see Qt::AlignmentFlag).

### void QListWidgetItem::setTextColor ( const QColor & color )

Sets the text color for the list item to the given color.

See also textColor() and setBackgroundColor().

### void QListWidgetItem::setToolTip ( const QString & toolTip )

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

See also toolTip(), setStatusTip(), and setWhatsThis().

### void QListWidgetItem::setWhatsThis ( const QString & whatsThis )

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

See also whatsThis(), setStatusTip(), and setToolTip().

### QString QListWidgetItem::statusTip () const

Returns the list item's status tip.

See also setStatusTip().

### QString QListWidgetItem::text () const

Returns the list item's text.

See also setText().

### int QListWidgetItem::textAlignment () const

Returns the text alignment for the list item (see Qt::AlignmentFlag).

### QColor QListWidgetItem::textColor () const

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

See also setTextColor() and backgroundColor().

### QString QListWidgetItem::toolTip () const

Returns the list item's tooltip.

See also setToolTip(), statusTip(), and whatsThis().

### QString QListWidgetItem::whatsThis () const

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

See also setWhatsThis(), statusTip(), and toolTip().

### 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.