
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQListWidgetItem class provides an item for use with theQListWidget item view class.More...
| Header: | #include <QListWidgetItem> |
| enum | ItemType { Type, UserType } |
| QListWidgetItem(QListWidget * parent = 0, int type = Type) | |
| QListWidgetItem(const QString & text, QListWidget * parent = 0, int type = Type) | |
| QListWidgetItem(const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type) | |
| QListWidgetItem(const QListWidgetItem & other) | |
| virtual | ~QListWidgetItem() |
| QBrush | background() 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 |
| QListWidget * | listWidget() const |
| virtual void | read(QDataStream & in) |
| void | setBackground(const QBrush & brush) |
| 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 | setToolTip(const QString & toolTip) |
| void | setWhatsThis(const QString & whatsThis) |
| QSize | sizeHint() const |
| QString | statusTip() const |
| QString | text() const |
| int | textAlignment() const |
| QString | toolTip() const |
| int | type() const |
| QString | whatsThis() const |
| virtual void | write(QDataStream & out) const |
| virtual bool | operator<(const QListWidgetItem & other) const |
| QListWidgetItem & | operator=(const QListWidgetItem & other) |
| QDataStream & | operator<<(QDataStream & out, const QListWidgetItem & item) |
| QDataStream & | operator>>(QDataStream & in, QListWidgetItem & item) |
TheQListWidgetItem class provides an item for use with theQListWidget item view class.
AQListWidgetItem represents a single item in aQListWidget. 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 theQListView class with a standard model.
List items can be inserted automatically into a list, when they are constructed, by specifying the list widget:
newQListWidgetItem(tr("Hazel"), listWidget);
Alternatively, list items can also be created without a parent widget, and later inserted into a list usingQListWidget::insertItem().
List items are typically used to displaytext() and anicon(). These are set with thesetText() andsetIcon() functions. The appearance of the text can be customized withsetFont(),setForeground(), andsetBackground(). Text in list items can be aligned using thesetTextAlignment() function. Tooltips, status tips and "What's This?" help can be added to list items withsetToolTip(),setStatusTip(), andsetWhatsThis().
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 callingsetFlags() with the appropriate value (seeQt::ItemFlags). Checkable items can be checked, unchecked and partially checked with thesetCheckState() function. The correspondingcheckState() function indicates the item's current check state.
TheisHidden() function can be used to determine whether the item is hidden. To hide an item, usesetHidden().
When subclassingQListWidgetItem 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 thanUserType, withinyour constructor.
See alsoQListWidget,Model/View Programming,QTreeWidgetItem, andQTableWidgetItem.
This enum describes the types that are used to describe list widget items.
| Constant | Value | Description |
|---|---|---|
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 inQListWidgetItem subclasses to ensure that custom items are treated specially.
See alsotype().
Constructs an empty list widget item of the specifiedtype with the givenparent. Ifparent is not specified, the item will need to be inserted into a list widget withQListWidget::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 useQListWidget::insertItem() instead.
See alsotype().
Constructs an empty list widget item of the specifiedtype with the giventext andparent. If the parent is not specified, the item will need to be inserted into a list widget withQListWidget::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 useQListWidget::insertItem() instead.
See alsotype().
Constructs an empty list widget item of the specifiedtype with the givenicon,text andparent. If the parent is not specified, the item will need to be inserted into a list widget withQListWidget::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 useQListWidget::insertItem() instead.
See alsotype().
Constructs a copy ofother. Note thattype() andlistWidget() are not copied.
This function is useful when reimplementingclone().
This function was introduced in Qt 4.1.
[virtual]QListWidgetItem::~QListWidgetItem()Destroys the list item.
Returns the brush used to display the list item's background.
This function was introduced in Qt 4.2.
See alsosetBackground() andforeground().
Returns the checked state of the list item (seeQt::CheckState).
See alsosetCheckState() andflags().
[virtual]QListWidgetItem * QListWidgetItem::clone() constCreates an exact copy of the item.
[virtual]QVariant QListWidgetItem::data(int role) constReturns the item's data for a givenrole. Reimplement this function if you need extra roles or special behavior for certain roles.
See alsoQt::ItemDataRole andsetData().
Returns the item flags for this item (seeQt::ItemFlags).
See alsosetFlags().
Returns the font used to display this list item's text.
See alsosetFont().
Returns the brush used to display the list item's foreground (e.g. text).
This function was introduced in Qt 4.2.
See alsosetForeground() andbackground().
Returns the list item's icon.
See alsosetIcon() andiconSize.
Returns true if the item is hidden; otherwise returns false.
This function was introduced in Qt 4.2.
See alsosetHidden().
Returns true if the item is selected; otherwise returns false.
This function was introduced in Qt 4.2.
See alsosetSelected().
Returns the list widget containing the item.
[virtual]void QListWidgetItem::read(QDataStream & in)Reads the item from streamin.
See alsowrite().
Sets the background brush of the list item to the givenbrush.
This function was introduced in Qt 4.2.
See alsobackground() andsetForeground().
Sets the check state of the list item tostate.
See alsocheckState().
[virtual]void QListWidgetItem::setData(int role, constQVariant & value)Sets the data for a givenrole to the givenvalue. Reimplement this function if you need extra roles or special behavior for certain roles.
See alsoQt::ItemDataRole anddata().
Sets the item flags for the list item toflags.
See alsoflags() andQt::ItemFlags.
Sets the font used when painting the item to the givenfont.
See alsofont().
Sets the foreground brush of the list item to the givenbrush.
This function was introduced in Qt 4.2.
See alsoforeground() andsetBackground().
Hides the item ifhide is true; otherwise shows the item.
This function was introduced in Qt 4.2.
See alsoisHidden().
Sets the icon for the list item to the givenicon.
See alsoicon(),text(), andiconSize.
Sets the selected state of the item toselect.
This function was introduced in Qt 4.2.
See alsoisSelected().
Sets the size hint for the list item to besize. If no size hint is set, the item delegate will compute the size hint based on the item data.
This function was introduced in Qt 4.1.
See alsosizeHint().
Sets the status tip for the list item to the text specified bystatusTip.QListWidget mouseTracking needs to be enabled for this feature to work.
See alsostatusTip(),setToolTip(),setWhatsThis(), andQWidget::setMouseTracking().
Sets the text for the list widget item's to the giventext.
See alsotext().
Sets the list item's text alignment toalignment.
See alsotextAlignment() andQt::AlignmentFlag.
Sets the tooltip for the list item to the text specified bytoolTip.
See alsotoolTip(),setStatusTip(), andsetWhatsThis().
Sets the "What's This?" help for the list item to the text specified bywhatsThis.
See alsowhatsThis(),setStatusTip(), andsetToolTip().
Returns the size hint set for the list item.
This function was introduced in Qt 4.1.
See alsosetSizeHint().
Returns the list item's status tip.
See alsosetStatusTip().
Returns the list item's text.
See alsosetText().
Returns the text alignment for the list item.
See alsosetTextAlignment() andQt::AlignmentFlag.
Returns the list item's tooltip.
See alsosetToolTip(),statusTip(), andwhatsThis().
Returns the type passed to theQListWidgetItem constructor.
Returns the list item's "What's This?" help text.
See alsosetWhatsThis(),statusTip(), andtoolTip().
[virtual]void QListWidgetItem::write(QDataStream & out) constWrites the item to streamout.
See alsoread().
[virtual]bool QListWidgetItem::operator<(constQListWidgetItem & other) constReturns true if this item's text is less thenother item's text; otherwise returns false.
Assignsother's data and flags to this item. Note thattype() andlistWidget() are not copied.
This function is useful when reimplementingclone().
Writes the list widget itemitem to streamout.
This operator usesQListWidgetItem::write().
See alsoSerializing Qt Data Types.
Reads a list widget item from streamin intoitem.
This operator usesQListWidgetItem::read().
See alsoSerializing Qt Data Types.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.