QListWidgetItem Class Reference

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

  1. #include <QListWidgetItem>

Detailed Description

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

A QListWidgetItem represents 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 QListView class with a standard model.

List items can be inserted automatically into a list, when they are constructed, by specifying the list widget:

  1.     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, Model/View Programming, QTreeWidgetItem, and QTableWidgetItem.

Public Types

Toggle detailsenum QListWidgetItem::

ItemTypeItemType { Type , UserType 1000 ...} { Type , UserType 1000 }

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

ConstantValueDescription
QListWidgetItem::Type 0 The default type for list widget items.
QListWidgetItem::UserType 1000 The minimum value for custom types. Values below UserType are reserved by Qt.

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

See also type().

Look up this member in the source code.

    Public Functions

    Toggle details QListWidgetItem

    QListWidgetItemQListWidgetItem ( QListWidget *parent=0 , int type=Type ...) ( QListWidget *parent=0 , int type=Type )

    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.

    See also type().

    Look up this member in the source code.

    Toggle details QListWidgetItem

    QListWidgetItemQListWidgetItem ( const QString &text , QListWidget *parent=0 , int type=Type ...) ( const QString &text , QListWidget *parent=0 , int type=Type )

    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.

    See also type().

    Look up this member in the source code.

    Toggle details QListWidgetItem

    QListWidgetItemQListWidgetItem ( const QIcon &icon , const QString &text , QListWidget *parent=0 , int type=Type ...) ( const QIcon &icon , const QString &text , QListWidget *parent=0 , int type=Type )

    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.

    See also type().

    Look up this member in the source code.

    Toggle details QListWidgetItem

    QListWidgetItemQListWidgetItem ( const QListWidgetItem &other ) ( const QListWidgetItem &other )

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

    This function is useful when reimplementing clone().

    See also data() and flags().

    Look up this member in the source code.

    Toggle details QListWidgetItem

    ~QListWidgetItem~QListWidgetItem () () [virtual]

    Destroys the list item.

    Look up this member in the source code.

    Toggle details QBrush QListWidgetItem

    backgroundbackground () ()const

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

    See also setBackground() and foreground().

    Look up this member in the source code.

    Toggle details Qt::CheckState QListWidgetItem

    checkStatecheckState () ()const

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

    See also setCheckState() and flags().

    Look up this member in the source code.

    Toggle details QListWidgetItem * QListWidgetItem

    cloneclone () ()const [virtual]

    Creates an exact copy of the item.

    Look up this member in the source code.

    Toggle details QVariant QListWidgetItem

    datadata ( int role ) ( 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 Qt::ItemDataRole and setData().

    Look up this member in the source code.

    Toggle details Qt::ItemFlags QListWidgetItem

    flagsflags () ()const

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

    See also setFlags().

    Look up this member in the source code.

    Toggle details QFont QListWidgetItem

    fontfont () ()const

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

    See also setFont().

    Look up this member in the source code.

    Toggle details QBrush QListWidgetItem

    foregroundforeground () ()const

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

    See also setForeground() and background().

    Look up this member in the source code.

    Toggle details QIcon QListWidgetItem

    iconicon () ()const

    Returns the list item's icon.

    See also setIcon() and iconSize.

    Look up this member in the source code.

    Toggle details bool QListWidgetItem

    isHiddenisHidden () ()const

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

    See also setHidden().

    Look up this member in the source code.

    Toggle details bool QListWidgetItem

    isSelectedisSelected () ()const

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

    See also setSelected().

    Look up this member in the source code.

    Toggle details QListWidget * QListWidgetItem

    listWidgetlistWidget () ()const

    Returns the list widget containing the item.

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    readread ( QDataStream &in ) ( QDataStream &in ) [virtual]

    Reads the item from stream in.

    See also write().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setBackgroundsetBackground ( const QBrush &brush ) ( const QBrush &brush )

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

    See also background() and setForeground().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setCheckStatesetCheckState ( Qt::CheckState state ) ( Qt::CheckState state )

    Sets the check state of the list item to state.

    See also checkState().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setDatasetData ( int role , const QVariant &value ) ( 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 Qt::ItemDataRole and data().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setFlagssetFlags ( Qt::ItemFlags flags ) ( Qt::ItemFlags flags )

    Sets the item flags for the list item to flags.

    See also flags() and Qt::ItemFlags.

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setFontsetFont ( const QFont &font ) ( const QFont &font )

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

    See also font().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setForegroundsetForeground ( const QBrush &brush ) ( const QBrush &brush )

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

    See also foreground() and setBackground().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setHiddensetHidden ( bool hide ) ( bool hide )

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

    See also isHidden().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setIconsetIcon ( const QIcon &icon ) ( const QIcon &icon )

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

    See also icon(), text(), and iconSize.

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setSelectedsetSelected ( bool select ) ( bool select )

    Sets the selected state of the item to select.

    See also isSelected().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setSizeHintsetSizeHint ( const QSize &size ) ( const QSize &size )

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

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setStatusTipsetStatusTip ( const QString &statusTip ) ( const QString &statusTip )

    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(), and QWidget::setMouseTracking().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setTextsetText ( const QString &text ) ( const QString &text )

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

    See also text().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setTextAlignmentsetTextAlignment ( int alignment ) ( int alignment )

    Sets the list item's text alignment to alignment.

    See also textAlignment() and Qt::AlignmentFlag.

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setToolTipsetToolTip ( const QString &toolTip ) ( const QString &toolTip )

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

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

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setWhatsThissetWhatsThis ( const QString &whatsThis ) ( 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().

    Look up this member in the source code.

    Toggle details QSize QListWidgetItem

    sizeHintsizeHint () ()const

    Returns the size hint set for the list item.

    See also setSizeHint().

    Look up this member in the source code.

    Toggle details QString QListWidgetItem

    statusTipstatusTip () ()const

    Returns the list item's status tip.

    See also setStatusTip().

    Look up this member in the source code.

    Toggle details QString QListWidgetItem

    texttext () ()const

    Returns the list item's text.

    See also setText().

    Look up this member in the source code.

    Toggle details int QListWidgetItem

    textAlignmenttextAlignment () ()const

    Returns the text alignment for the list item.

    See also setTextAlignment() and Qt::AlignmentFlag.

    Look up this member in the source code.

    Toggle details QString QListWidgetItem

    toolTiptoolTip () ()const

    Returns the list item's tooltip.

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

    Look up this member in the source code.

    Toggle details int QListWidgetItem

    typetype () ()const

    Returns the type passed to the QListWidgetItem constructor.

    Look up this member in the source code.

    Toggle details QString QListWidgetItem

    whatsThiswhatsThis () ()const

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

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

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    writewrite ( QDataStream &out ) ( QDataStream &out )const [virtual]

    Writes the item to stream out.

    See also read().

    Look up this member in the source code.

    Toggle details bool QListWidgetItem

    operator<operator< ( const QListWidgetItem &other ) ( const QListWidgetItem &other )const [virtual]

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

    Look up this member in the source code.

    Toggle details QListWidgetItem & QListWidgetItem

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

    Assigns other's data and flags to this item. Note that type() and listWidget() are not copied.

    This function is useful when reimplementing clone().

    See also data() and flags().

    Look up this member in the source code.

    Toggle details QColor QListWidgetItem

    backgroundColorbackgroundColor () ()const Obsolete function

    This function is deprecated. Use background() instead.

    See also setBackgroundColor().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setBackgroundColorsetBackgroundColor ( const QColor &color ) ( const QColor &color ) [virtual] Obsolete function

    This function is deprecated. Use setBackground() instead.

    See also backgroundColor().

    Look up this member in the source code.

    Toggle details void QListWidgetItem

    setTextColorsetTextColor ( const QColor &color ) ( const QColor &color ) Obsolete function

    This function is deprecated. Use setForeground() instead.

    See also textColor().

    Look up this member in the source code.

    Toggle details QColor QListWidgetItem

    textColortextColor () ()const Obsolete function

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

    This function is deprecated. Use foreground() instead.

    See also setTextColor().

    Look up this member in the source code.

    Notes provided by the Qt Community

    No notes