Qt 4.8
Public Types | Public Functions | Properties | Friends | Related Functions | List of all members
QListWidgetItem Class Reference

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

#include <qlistwidget.h>

Public Types

enum  ItemType { Type = 0, UserType = 1000 }
 This enum describes the types that are used to describe list widget items. More...
 

Public Functions

QBrush background () const
 Returns the brush used to display the list item's background. More...
 
QColor backgroundColor () const
 This function is deprecated. More...
 
Qt::CheckState checkState () const
 Returns the checked state of the list item (see Qt::CheckState). More...
 
virtual QListWidgetItemclone () const
 Creates an exact copy of the item. More...
 
virtual QVariant data (int role) const
 Returns the item's data for a given role. More...
 
Qt::ItemFlags flags () const
 Returns the item flags for this item (see Qt::ItemFlags). More...
 
QFont font () const
 Returns the font used to display this list item's text. More...
 
QBrush foreground () const
 Returns the brush used to display the list item's foreground (e. More...
 
QIcon icon () const
 Returns the list item's icon. More...
 
bool isHidden () const
 Returns true if the item is hidden; otherwise returns false. More...
 
bool isSelected () const
 Returns true if the item is selected; otherwise returns false. More...
 
QListWidgetlistWidget () const
 Returns the list widget containing the item. More...
 
virtual bool operator< (const QListWidgetItem &other) const
 Returns true if this item's text is less then other item's text; otherwise returns false. More...
 
QListWidgetItemoperator= (const QListWidgetItem &other)
 Assigns other's data and flags to this item. More...
 
 QListWidgetItem (QListWidget *view=0, int type=Type)
 Constructs an empty list widget item of the specified type with the given parent. More...
 
 QListWidgetItem (const QString &text, QListWidget *view=0, int type=Type)
 Constructs an empty list widget item of the specified type with the given text and parent. More...
 
 QListWidgetItem (const QIcon &icon, const QString &text, QListWidget *view=0, int type=Type)
 Constructs an empty list widget item of the specified type with the given icon, text and parent. More...
 
 QListWidgetItem (const QListWidgetItem &other)
 Constructs a copy of other. More...
 
virtual void read (QDataStream &in)
 Reads the item from stream in. More...
 
void setBackground (const QBrush &brush)
 Sets the background brush of the list item to the given brush. More...
 
virtual void setBackgroundColor (const QColor &color)
 This function is deprecated. More...
 
void setCheckState (Qt::CheckState state)
 Sets the check state of the list item to state. More...
 
virtual void setData (int role, const QVariant &value)
 Sets the data for a given role to the given value. More...
 
void setFlags (Qt::ItemFlags flags)
 Sets the item flags for the list item to flags. More...
 
void setFont (const QFont &font)
 Sets the font used when painting the item to the given font. More...
 
void setForeground (const QBrush &brush)
 Sets the foreground brush of the list item to the given brush. More...
 
void setHidden (bool hide)
 Hides the item if hide is true; otherwise shows the item. More...
 
void setIcon (const QIcon &icon)
 Sets the icon for the list item to the given icon. More...
 
void setSelected (bool select)
 Sets the selected state of the item to select. More...
 
void setSizeHint (const QSize &size)
 Sets the size hint for the list item to be size. More...
 
void setStatusTip (const QString &statusTip)
 Sets the status tip for the list item to the text specified by statusTip. More...
 
void setText (const QString &text)
 Sets the text for the list widget item's to the given text. More...
 
void setTextAlignment (int alignment)
 Sets the list item's text alignment to alignment. More...
 
void setTextColor (const QColor &color)
 This function is deprecated. More...
 
void setToolTip (const QString &toolTip)
 Sets the tooltip for the list item to the text specified by toolTip. More...
 
void setWhatsThis (const QString &whatsThis)
 Sets the "What's This?" help for the list item to the text specified by whatsThis. More...
 
QSize sizeHint () const
 Returns the size hint set for the list item. More...
 
QString statusTip () const
 Returns the list item's status tip. More...
 
QString text () const
 Returns the list item's text. More...
 
int textAlignment () const
 Returns the text alignment for the list item. More...
 
QColor textColor () const
 Returns the color used to display the list item's text. More...
 
QString toolTip () const
 Returns the list item's tooltip. More...
 
int type () const
 Returns the type passed to the QListWidgetItem constructor. More...
 
QString whatsThis () const
 Returns the list item's "What's This?" help text. More...
 
virtual void write (QDataStream &out) const
 Writes the item to stream out. More...
 
virtual ~QListWidgetItem ()
 Destroys the list item. More...
 

Properties

QListWidgetItemPrivated
 
QVector< void * > dummy
 
Qt::ItemFlags itemFlags
 
int rtti
 
QListWidgetview
 

Friends

class QListModel
 
class QListWidget
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QListWidgetItem &item)
 Writes the list widget item item to stream out. More...
 
QDataStreamoperator>> (QDataStream &in, QListWidgetItem &item)
 Reads a list widget item from stream in into item. More...
 

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:

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, QTableWidgetItem

Definition at line 63 of file qlistwidget.h.

Enumerations

◆ ItemType

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

  • Type The default type for list widget items.
  • UserType 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()
Enumerator
Type 
UserType 

Definition at line 68 of file qlistwidget.h.

Constructors and Destructors

◆ QListWidgetItem() [1/4]

QListWidgetItem::QListWidgetItem ( QListWidget parent = 0,
int  type = Type 
)
explicit

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

Definition at line 610 of file qlistwidget.cpp.

Referenced by clone().

611  : rtti(type), view(view), d(new QListWidgetItemPrivate(this)),
616 {
617  if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
618  model->insert(model->rowCount(), this);
619 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
Qt::ItemFlags itemFlags
Definition: qlistwidget.h:170
QListWidget * view
Definition: qlistwidget.h:168
int type() const
Returns the type passed to the QListWidgetItem constructor.
Definition: qlistwidget.h:163
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ QListWidgetItem() [2/4]

QListWidgetItem::QListWidgetItem ( const QString text,
QListWidget parent = 0,
int  type = Type 
)
explicit

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

Definition at line 637 of file qlistwidget.cpp.

638  : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),
643 {
644  setData(Qt::DisplayRole, text);
645  this->view = view;
646  if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
647  model->insert(model->rowCount(), this);
648 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.
Qt::ItemFlags itemFlags
Definition: qlistwidget.h:170
QListWidget * view
Definition: qlistwidget.h:168
int type() const
Returns the type passed to the QListWidgetItem constructor.
Definition: qlistwidget.h:163
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ QListWidgetItem() [3/4]

QListWidgetItem::QListWidgetItem ( const QIcon icon,
const QString text,
QListWidget parent = 0,
int  type = Type 
)
explicit

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

Definition at line 667 of file qlistwidget.cpp.

669  : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),
674 {
675  setData(Qt::DisplayRole, text);
677  this->view = view;
678  if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
679  model->insert(model->rowCount(), this);
680 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.
Qt::ItemFlags itemFlags
Definition: qlistwidget.h:170
QListWidget * view
Definition: qlistwidget.h:168
int type() const
Returns the type passed to the QListWidgetItem constructor.
Definition: qlistwidget.h:163
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ QListWidgetItem() [4/4]

QListWidgetItem::QListWidgetItem ( const QListWidgetItem other)

Constructs a copy of other.

Since
4.1

Note that type() and listWidget() are not copied.

This function is useful when reimplementing clone().

See also
data(), flags()

Definition at line 786 of file qlistwidget.cpp.

787  : rtti(Type), view(0),
788  d(new QListWidgetItemPrivate(this)),
789  itemFlags(other.itemFlags)
790 {
791  d->values = other.d->values;
792 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
QVector< QWidgetItemData > values
Qt::ItemFlags itemFlags
Definition: qlistwidget.h:170
QListWidget * view
Definition: qlistwidget.h:168

◆ ~QListWidgetItem()

QListWidgetItem::~QListWidgetItem ( )
virtual

Destroys the list item.

Definition at line 685 of file qlistwidget.cpp.

686 {
687  if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
688  model->remove(this);
689  delete d;
690 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
QListWidget * view
Definition: qlistwidget.h:168
QAbstractItemModel * model() const
Returns the model that this view is presenting.

Functions

◆ background()

QBrush QListWidgetItem::background ( ) const
inline

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

Since
4.2
See also
setBackground() foreground()

Definition at line 127 of file qlistwidget.h.

virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ backgroundColor()

QColor QListWidgetItem::backgroundColor ( ) const
inline

This function is deprecated.

Use background() instead.

Definition at line 122 of file qlistwidget.h.

The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ checkState()

Qt::CheckState QListWidgetItem::checkState ( ) const
inline

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

See also
flags()

Definition at line 142 of file qlistwidget.h.

143  { return static_cast<Qt::CheckState>(data(Qt::CheckStateRole).toInt()); }
CheckState
Definition: qnamespace.h:1607
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.

◆ clone()

QListWidgetItem * QListWidgetItem::clone ( ) const
virtual

Creates an exact copy of the item.

Definition at line 695 of file qlistwidget.cpp.

696 {
697  return new QListWidgetItem(*this);
698 }
QListWidgetItem(QListWidget *view=0, int type=Type)
Constructs an empty list widget item of the specified type with the given parent. ...

◆ data()

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
Qt::ItemDataRole, setData()

Definition at line 731 of file qlistwidget.cpp.

Referenced by operator<().

732 {
733  role = (role == Qt::EditRole ? Qt::DisplayRole : role);
734  for (int i = 0; i < d->values.count(); ++i)
735  if (d->values.at(i).role == role)
736  return d->values.at(i).value;
737  return QVariant();
738 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
QVector< QWidgetItemData > values
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350

◆ flags()

Qt::ItemFlags QListWidgetItem::flags ( ) const
inline

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

Definition at line 86 of file qlistwidget.h.

86 { return itemFlags; }
Qt::ItemFlags itemFlags
Definition: qlistwidget.h:170

◆ font()

QFont QListWidgetItem::font ( ) const
inline

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

Definition at line 113 of file qlistwidget.h.

114  { return qvariant_cast<QFont>(data(Qt::FontRole)); }
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ foreground()

QBrush QListWidgetItem::foreground ( ) const
inline

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

Since
4.2

g. text).

\sa setForeground() background()

Definition at line 137 of file qlistwidget.h.

virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ icon()

QIcon QListWidgetItem::icon ( ) const
inline

Returns the list item's icon.

See also
setIcon(), {QAbstractItemView::iconSize}{iconSize}

Definition at line 93 of file qlistwidget.h.

virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ isHidden()

bool QListWidgetItem::isHidden ( ) const
inline

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

Since
4.2
See also
setHidden()

Definition at line 326 of file qlistwidget.h.

327 { return (view ? view->isItemHidden(this) : false); }
bool isItemHidden(const QListWidgetItem *item) const
Returns true if the item is explicitly hidden; otherwise returns false.
QListWidget * view
Definition: qlistwidget.h:168

◆ isSelected()

bool QListWidgetItem::isSelected ( ) const
inline

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

Since
4.2
See also
setSelected()

Definition at line 320 of file qlistwidget.h.

321 { return (view ? view->isItemSelected(this) : false); }
QListWidget * view
Definition: qlistwidget.h:168
bool isItemSelected(const QListWidgetItem *item) const
Returns true if item is selected; otherwise returns false.

◆ listWidget()

QListWidget * QListWidgetItem::listWidget ( ) const
inline

Returns the list widget containing the item.

Definition at line 78 of file qlistwidget.h.

78 { return view; }
QListWidget * view
Definition: qlistwidget.h:168

◆ operator<()

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.

Definition at line 744 of file qlistwidget.cpp.

745 {
746  const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole);
748 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static bool variantLessThan(const QVariant &v1, const QVariant &v2)
This function is used by our Q{Tree,Widget,Table}WidgetModel classes to sort.
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.

◆ operator=()

QListWidgetItem & QListWidgetItem::operator= ( 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(), flags()

Definition at line 802 of file qlistwidget.cpp.

803 {
804  d->values = other.d->values;
805  itemFlags = other.itemFlags;
806  return *this;
807 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
QVector< QWidgetItemData > values
Qt::ItemFlags itemFlags
Definition: qlistwidget.h:170

◆ read()

void QListWidgetItem::read ( QDataStream in)
virtual

Reads the item from stream in.

See also
write()

Definition at line 757 of file qlistwidget.cpp.

Referenced by operator>>().

758 {
759  in >> d->values;
760 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
QVector< QWidgetItemData > values

◆ setBackground()

void QListWidgetItem::setBackground ( const QBrush brush)
inline

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

Since
4.2
See also
background() setForeground()

Definition at line 129 of file qlistwidget.h.

130  { setData(Qt::BackgroundRole, brush); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setBackgroundColor()

void QListWidgetItem::setBackgroundColor ( const QColor color)
inlinevirtual

This function is deprecated.

Use setBackground() instead.

Definition at line 124 of file qlistwidget.h.

125  { setData(Qt::BackgroundColorRole, color); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setCheckState()

void QListWidgetItem::setCheckState ( Qt::CheckState  state)
inline

Sets the check state of the list item to state.

See also
checkState()

Definition at line 144 of file qlistwidget.h.

145  { setData(Qt::CheckStateRole, static_cast<int>(state)); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setData()

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
Qt::ItemDataRole, data()

Definition at line 706 of file qlistwidget.cpp.

Referenced by QListWidgetItem().

707 {
708  bool found = false;
709  role = (role == Qt::EditRole ? Qt::DisplayRole : role);
710  for (int i = 0; i < d->values.count(); ++i) {
711  if (d->values.at(i).role == role) {
712  if (d->values.at(i).value == value)
713  return;
714  d->values[i].value = value;
715  found = true;
716  break;
717  }
718  }
719  if (!found)
720  d->values.append(QWidgetItemData(role, value));
721  if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
722  model->itemChanged(this);
723 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
T value(int i) const
Returns the value at index position i in the vector.
Definition: qvector.h:559
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QVector< QWidgetItemData > values
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QListWidget * view
Definition: qlistwidget.h:168
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ setFlags()

void QListWidgetItem::setFlags ( Qt::ItemFlags  flags)

Sets the item flags for the list item to flags.

See also
Qt::ItemFlags

Definition at line 1021 of file qlistwidget.cpp.

1021  {
1022  itemFlags = aflags;
1023  if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
1024  model->itemChanged(this);
1025 }
Qt::ItemFlags itemFlags
Definition: qlistwidget.h:170
QListWidget * view
Definition: qlistwidget.h:168
QAbstractItemModel * model() const
Returns the model that this view is presenting.

◆ setFont()

void QListWidgetItem::setFont ( const QFont font)
inline

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

Definition at line 192 of file qlistwidget.h.

193 { setData(Qt::FontRole, afont); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setForeground()

void QListWidgetItem::setForeground ( const QBrush brush)
inline

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

Since
4.2
See also
foreground() setBackground()

Definition at line 139 of file qlistwidget.h.

140  { setData(Qt::ForegroundRole, brush); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setHidden()

void QListWidgetItem::setHidden ( bool  hide)
inline

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

Since
4.2
See also
isHidden()

Definition at line 323 of file qlistwidget.h.

324 { if (view) view->setItemHidden(this, ahide); }
void setItemHidden(const QListWidgetItem *item, bool hide)
If hide is true, the item will be hidden; otherwise it will be shown.
QListWidget * view
Definition: qlistwidget.h:168

◆ setIcon()

void QListWidgetItem::setIcon ( const QIcon icon)
inline

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

See also
icon(), text(), {QAbstractItemView::iconSize}{iconSize}

Definition at line 176 of file qlistwidget.h.

177 { setData(Qt::DecorationRole, aicon); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setSelected()

void QListWidgetItem::setSelected ( bool  select)
inline

Sets the selected state of the item to select.

Since
4.2
See also
isSelected()

Definition at line 317 of file qlistwidget.h.

318 { if (view) view->setItemSelected(this, aselect); }
void setItemSelected(const QListWidgetItem *item, bool select)
Selects or deselects the given item depending on whether select is true of false. ...
QListWidget * view
Definition: qlistwidget.h:168

◆ setSizeHint()

void QListWidgetItem::setSizeHint ( const QSize size)
inline

Sets the size hint for the list item to be size.

Since
4.1

If no size hint is set, the item delegate will compute the size hint based on the item data.

Definition at line 149 of file qlistwidget.h.

150  { setData(Qt::SizeHintRole, size); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setStatusTip()

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

Definition at line 179 of file qlistwidget.h.

180 { setData(Qt::StatusTipRole, astatusTip); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setText()

void QListWidgetItem::setText ( const QString text)
inline

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

See also
text()

Definition at line 173 of file qlistwidget.h.

174 { setData(Qt::DisplayRole, atext); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setTextAlignment()

void QListWidgetItem::setTextAlignment ( int  alignment)
inline

Sets the list item's text alignment to alignment.

See also
Qt::AlignmentFlag

Definition at line 119 of file qlistwidget.h.

120  { setData(Qt::TextAlignmentRole, alignment); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setTextColor()

void QListWidgetItem::setTextColor ( const QColor color)
inline

This function is deprecated.

Use setForeground() instead.

Definition at line 134 of file qlistwidget.h.

135  { setData(Qt::TextColorRole, color); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ setToolTip()

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

Definition at line 183 of file qlistwidget.h.

184 { setData(Qt::ToolTipRole, atoolTip); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

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

Definition at line 188 of file qlistwidget.h.

189 { setData(Qt::WhatsThisRole, awhatsThis); }
virtual void setData(int role, const QVariant &value)
Sets the data for a given role to the given value.

◆ sizeHint()

QSize QListWidgetItem::sizeHint ( ) const
inline

Returns the size hint set for the list item.

Since
4.1

Definition at line 147 of file qlistwidget.h.

virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ statusTip()

QString QListWidgetItem::statusTip ( ) const
inline

Returns the list item's status tip.

See also
setStatusTip()

Definition at line 97 of file qlistwidget.h.

98  { return data(Qt::StatusTipRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.

◆ text()

QString QListWidgetItem::text ( ) const
inline

Returns the list item's text.

See also
setText()

Definition at line 89 of file qlistwidget.h.

Referenced by QListWidgetPrivate::_q_emitCurrentItemChanged().

90  { return data(Qt::DisplayRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.

◆ textAlignment()

int QListWidgetItem::textAlignment ( ) const
inline

Returns the text alignment for the list item.

See also
Qt::AlignmentFlag

Definition at line 117 of file qlistwidget.h.

118  { return data(Qt::TextAlignmentRole).toInt(); }
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.

◆ textColor()

QColor QListWidgetItem::textColor ( ) const
inline

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

This function is deprecated. Use foreground() instead.

Definition at line 132 of file qlistwidget.h.

The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ toolTip()

QString QListWidgetItem::toolTip ( ) const
inline

Returns the list item's tooltip.

See also
setToolTip() statusTip() whatsThis()

Definition at line 102 of file qlistwidget.h.

103  { return data(Qt::ToolTipRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.

◆ type()

int QListWidgetItem::type ( ) const
inline

Returns the type passed to the QListWidgetItem constructor.

Definition at line 163 of file qlistwidget.h.

163 { return rtti; }

◆ whatsThis()

QString QListWidgetItem::whatsThis ( ) const
inline

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

See also
setWhatsThis() statusTip() toolTip()

Definition at line 108 of file qlistwidget.h.

109  { return data(Qt::WhatsThisRole).toString(); }
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
virtual QVariant data(int role) const
Returns the item&#39;s data for a given role.

◆ write()

void QListWidgetItem::write ( QDataStream out) const
virtual

Writes the item to stream out.

See also
read()

Definition at line 767 of file qlistwidget.cpp.

Referenced by operator<<().

768 {
769  out << d->values;
770 }
QListWidgetItemPrivate * d
Definition: qlistwidget.h:169
QVector< QWidgetItemData > values

Friends and Related Functions

◆ operator<<()

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

Writes the list widget item item to stream out.

This operator uses QListWidgetItem::write().

See also
{Serializing Qt Data Types}

Definition at line 823 of file qlistwidget.cpp.

824 {
825  item.write(out);
826  return out;
827 }
virtual void write(QDataStream &out) const
Writes the item to stream out.

◆ operator>>()

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

Reads a list widget item from stream in into item.

This operator uses QListWidgetItem::read().

See also
{Serializing Qt Data Types}

Definition at line 841 of file qlistwidget.cpp.

842 {
843  item.read(in);
844  return in;
845 }
virtual void read(QDataStream &in)
Reads the item from stream in.

◆ QListModel

friend class QListModel
friend

Definition at line 65 of file qlistwidget.h.

Referenced by QListWidgetPrivate::setup().

◆ QListWidget

friend class QListWidget
friend

Definition at line 66 of file qlistwidget.h.

Properties

◆ d

QListWidgetItemPrivate* QListWidgetItem::d
private

◆ dummy

QVector<void *> QListWidgetItem::dummy
private

Definition at line 167 of file qlistwidget.h.

◆ itemFlags

Qt::ItemFlags QListWidgetItem::itemFlags
private

Definition at line 170 of file qlistwidget.h.

Referenced by operator=(), and setFlags().

◆ rtti

int QListWidgetItem::rtti
private

Definition at line 166 of file qlistwidget.h.

◆ view

QListWidget* QListWidgetItem::view
private

The documentation for this class was generated from the following files: