Qt 4.8
|
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 QListWidgetItem * | clone () 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... | |
QListWidget * | listWidget () 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... | |
QListWidgetItem & | operator= (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 | |
QListWidgetItemPrivate * | d |
QVector< void * > | dummy |
Qt::ItemFlags | itemFlags |
int | rtti |
QListWidget * | view |
Friends | |
class | QListModel |
class | QListWidget |
Related Functions | |
(Note that these are not member functions.) | |
QDataStream & | operator<< (QDataStream &out, const QListWidgetItem &item) |
Writes the list widget item item to stream out. More... | |
QDataStream & | operator>> (QDataStream &in, QListWidgetItem &item) |
Reads a list widget item from stream in into item. More... | |
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:
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().
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.
Definition at line 63 of file qlistwidget.h.
This enum describes the types that are used to describe list widget items.
You can define new user types in QListWidgetItem subclasses to ensure that custom items are treated specially.
Enumerator | |
---|---|
Type | |
UserType |
Definition at line 68 of file qlistwidget.h.
|
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.
Definition at line 610 of file qlistwidget.cpp.
Referenced by clone().
|
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.
Definition at line 637 of file qlistwidget.cpp.
|
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.
Definition at line 667 of file qlistwidget.cpp.
QListWidgetItem::QListWidgetItem | ( | const QListWidgetItem & | other | ) |
Constructs a copy of other.
Note that type() and listWidget() are not copied.
This function is useful when reimplementing clone().
Definition at line 786 of file qlistwidget.cpp.
|
virtual |
Destroys the list item.
Definition at line 685 of file qlistwidget.cpp.
|
inline |
Returns the brush used to display the list item's background.
Definition at line 127 of file qlistwidget.h.
|
inline |
This function is deprecated.
Use background() instead.
Definition at line 122 of file qlistwidget.h.
|
inline |
Returns the checked state of the list item (see Qt::CheckState).
Definition at line 142 of file qlistwidget.h.
|
virtual |
Creates an exact copy of the item.
Definition at line 695 of file qlistwidget.cpp.
|
virtual |
Returns the item's data for a given role.
Reimplement this function if you need extra roles or special behavior for certain roles.
Definition at line 731 of file qlistwidget.cpp.
Referenced by operator<().
|
inline |
Returns the item flags for this item (see Qt::ItemFlags).
Definition at line 86 of file qlistwidget.h.
|
inline |
Returns the font used to display this list item's text.
Definition at line 113 of file qlistwidget.h.
|
inline |
Returns the brush used to display the list item's foreground (e.
g. text).
\sa setForeground() background()
Definition at line 137 of file qlistwidget.h.
|
inline |
Returns the list item's icon.
Definition at line 93 of file qlistwidget.h.
|
inline |
Returns true if the item is hidden; otherwise returns false.
Definition at line 326 of file qlistwidget.h.
|
inline |
Returns true if the item is selected; otherwise returns false.
Definition at line 320 of file qlistwidget.h.
|
inline |
|
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.
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().
Definition at line 802 of file qlistwidget.cpp.
|
virtual |
Reads the item from stream in.
Definition at line 757 of file qlistwidget.cpp.
Referenced by operator>>().
|
inline |
Sets the background brush of the list item to the given brush.
Definition at line 129 of file qlistwidget.h.
|
inlinevirtual |
This function is deprecated.
Use setBackground() instead.
Definition at line 124 of file qlistwidget.h.
|
inline |
Sets the check state of the list item to state.
Definition at line 144 of file qlistwidget.h.
|
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.
Definition at line 706 of file qlistwidget.cpp.
Referenced by QListWidgetItem().
void QListWidgetItem::setFlags | ( | Qt::ItemFlags | flags | ) |
Sets the item flags for the list item to flags.
Definition at line 1021 of file qlistwidget.cpp.
|
inline |
Sets the font used when painting the item to the given font.
Definition at line 192 of file qlistwidget.h.
|
inline |
Sets the foreground brush of the list item to the given brush.
Definition at line 139 of file qlistwidget.h.
|
inline |
Hides the item if hide is true; otherwise shows the item.
Definition at line 323 of file qlistwidget.h.
|
inline |
Sets the icon for the list item to the given icon.
Definition at line 176 of file qlistwidget.h.
|
inline |
Sets the selected state of the item to select.
Definition at line 317 of file qlistwidget.h.
|
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.
Definition at line 149 of file qlistwidget.h.
|
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.
Definition at line 179 of file qlistwidget.h.
|
inline |
Sets the text for the list widget item's to the given text.
Definition at line 173 of file qlistwidget.h.
|
inline |
Sets the list item's text alignment to alignment.
Definition at line 119 of file qlistwidget.h.
|
inline |
This function is deprecated.
Use setForeground() instead.
Definition at line 134 of file qlistwidget.h.
|
inline |
Sets the tooltip for the list item to the text specified by toolTip.
Definition at line 183 of file qlistwidget.h.
|
inline |
Sets the "What's This?" help for the list item to the text specified by whatsThis.
Definition at line 188 of file qlistwidget.h.
|
inline |
Returns the size hint set for the list item.
Definition at line 147 of file qlistwidget.h.
|
inline |
Returns the list item's status tip.
Definition at line 97 of file qlistwidget.h.
|
inline |
Returns the list item's text.
Definition at line 89 of file qlistwidget.h.
Referenced by QListWidgetPrivate::_q_emitCurrentItemChanged().
|
inline |
Returns the text alignment for the list item.
Definition at line 117 of file qlistwidget.h.
|
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.
|
inline |
Returns the list item's tooltip.
Definition at line 102 of file qlistwidget.h.
|
inline |
Returns the type passed to the QListWidgetItem constructor.
Definition at line 163 of file qlistwidget.h.
|
inline |
Returns the list item's "What's This?" help text.
Definition at line 108 of file qlistwidget.h.
|
virtual |
Writes the item to stream out.
Definition at line 767 of file qlistwidget.cpp.
Referenced by operator<<().
|
related |
Writes the list widget item item to stream out.
This operator uses QListWidgetItem::write().
Definition at line 823 of file qlistwidget.cpp.
|
related |
Reads a list widget item from stream in into item.
This operator uses QListWidgetItem::read().
Definition at line 841 of file qlistwidget.cpp.
|
friend |
Definition at line 65 of file qlistwidget.h.
Referenced by QListWidgetPrivate::setup().
|
friend |
Definition at line 66 of file qlistwidget.h.
|
private |
Definition at line 169 of file qlistwidget.h.
Referenced by QListModel::clear(), data(), QListModel::index(), QListModel::insert(), QListModel::itemData(), operator=(), QListWidgetItem(), read(), QListModel::remove(), QListModel::removeRows(), setData(), QListModel::take(), write(), and ~QListWidgetItem().
|
private |
Definition at line 167 of file qlistwidget.h.
|
private |
Definition at line 170 of file qlistwidget.h.
Referenced by operator=(), and setFlags().
|
private |
Definition at line 166 of file qlistwidget.h.
|
private |
Definition at line 168 of file qlistwidget.h.
Referenced by QListModel::clear(), QListModel::index(), QListModel::insert(), QListWidget::insertItem(), QListModel::insertRows(), QListWidgetItem(), QListModel::remove(), QListModel::removeRows(), setData(), setFlags(), QListModel::take(), and ~QListWidgetItem().