Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
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 Member Functions | |
QListWidgetItem (QListWidget *listview=nullptr, int type=Type) | |
Constructs an empty list widget item of the specified type with the given parent. | |
QListWidgetItem (const QString &text, QListWidget *listview=nullptr, int type=Type) | |
Constructs an empty list widget item of the specified type with the given text and parent. | |
QListWidgetItem (const QIcon &icon, const QString &text, QListWidget *listview=nullptr, int type=Type) | |
Constructs an empty list widget item of the specified type with the given icon, text and parent. | |
QListWidgetItem (const QListWidgetItem &other) | |
Constructs a copy of other. | |
virtual | ~QListWidgetItem () |
Destroys the list item. | |
virtual QListWidgetItem * | clone () const |
Creates an exact copy of the item. | |
QListWidget * | listWidget () const |
Returns the list widget containing the item. | |
void | setSelected (bool select) |
Sets the selected state of the item to select. | |
bool | isSelected () const |
Returns true if the item is selected; otherwise returns false . | |
void | setHidden (bool hide) |
Hides the item if hide is true; otherwise shows the item. | |
bool | isHidden () const |
Returns true if the item is hidden; otherwise returns false . | |
Qt::ItemFlags | flags () const |
Returns the item flags for this item (see \l{Qt::ItemFlags}). | |
void | setFlags (Qt::ItemFlags flags) |
Sets the item flags for the list item to flags. | |
QString | text () const |
Returns the list item's text. | |
void | setText (const QString &text) |
Sets the text for the list widget item's to the given text. | |
QIcon | icon () const |
Returns the list item's icon. | |
void | setIcon (const QIcon &icon) |
Sets the icon for the list item to the given icon. | |
QString | statusTip () const |
Returns the list item's status tip. | |
void | setStatusTip (const QString &statusTip) |
Sets the status tip for the list item to the text specified by statusTip. | |
QFont | font () const |
Returns the font used to display this list item's text. | |
void | setFont (const QFont &font) |
Sets the font used when painting the item to the given font. | |
Qt::Alignment | textAlignment () const |
void | setTextAlignment (Qt::Alignment alignment) |
\obsolete [6.4] Use the overload that takes a Qt::Alignment argument. | |
QBrush | background () const |
Returns the brush used to display the list item's background. | |
void | setBackground (const QBrush &brush) |
Sets the background brush of the list item to the given brush. | |
QBrush | foreground () const |
Returns the brush used to display the list item's foreground (e.g. | |
void | setForeground (const QBrush &brush) |
Sets the foreground brush of the list item to the given brush. | |
Qt::CheckState | checkState () const |
Returns the checked state of the list item (see \l{Qt::CheckState}). | |
void | setCheckState (Qt::CheckState state) |
Sets the check state of the list item to state. | |
QSize | sizeHint () const |
Returns the size hint set for the list item. | |
void | setSizeHint (const QSize &size) |
Sets the size hint for the list item to be size. | |
virtual QVariant | data (int role) const |
Returns the item's data for a given role. | |
virtual void | setData (int role, const QVariant &value) |
Sets the data for a given role to the given value. | |
virtual bool | operator< (const QListWidgetItem &other) const |
Returns true if this item's text is less then other item's text; otherwise returns false . | |
virtual void | read (QDataStream &in) |
Reads the item from stream in. | |
virtual void | write (QDataStream &out) const |
Writes the item to stream out. | |
QListWidgetItem & | operator= (const QListWidgetItem &other) |
Assigns other's data and flags to this item. | |
int | type () const |
Returns the type passed to the QListWidgetItem constructor. | |
Friends | |
class | QListModel |
class | QListWidget |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator<< (QDataStream &out, const QListWidgetItem &item) |
Writes the list widget item item to stream out. | |
QDataStream & | operator>> (QDataStream &in, QListWidgetItem &item) |
Reads a list widget item from stream in into item. | |
The QListWidgetItem class provides an item for use with the QListWidget item view class.
\inmodule QtWidgets
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().
Definition at line 22 of file qlistwidget.h.
This enum describes the types that are used to describe list widget items.
\value Type The default type for list widget items. \value 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.
Enumerator | |
---|---|
Type | |
UserType |
Definition at line 27 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 549 of file qlistwidget.cpp.
|
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 576 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 610 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 735 of file qlistwidget.cpp.
|
virtual |
Destroys the list item.
Definition at line 632 of file qlistwidget.cpp.
|
inline |
Returns the brush used to display the list item's background.
Definition at line 93 of file qlistwidget.h.
|
inline |
Returns the checked state of the list item (see \l{Qt::CheckState}).
Definition at line 103 of file qlistwidget.h.
|
virtual |
Creates an exact copy of the item.
Definition at line 642 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 685 of file qlistwidget.cpp.
|
inline |
Returns the item flags for this item (see \l{Qt::ItemFlags}).
Definition at line 45 of file qlistwidget.h.
|
inline |
Returns the font used to display this list item's text.
Definition at line 72 of file qlistwidget.h.
|
inline |
Returns the brush used to display the list item's foreground (e.g.
text).
Definition at line 98 of file qlistwidget.h.
|
inline |
Returns the list item's icon.
Definition at line 52 of file qlistwidget.h.
|
inline |
Returns true
if the item is hidden; otherwise returns false
.
Definition at line 275 of file qlistwidget.h.
bool QListWidgetItem::isSelected | ( | ) | const |
Returns true
if the item is selected; otherwise returns false
.
Definition at line 945 of file qlistwidget.cpp.
|
inline |
Returns the list widget containing the item.
Definition at line 37 of file qlistwidget.h.
|
virtual |
Returns true
if this item's text is less then other item's text; otherwise returns false
.
Definition at line 698 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 751 of file qlistwidget.cpp.
|
virtual |
Sets the background brush of the list item to the given brush.
Setting a default-constructed brush will let the view use the default color from the style.
Definition at line 95 of file qlistwidget.h.
|
inline |
Sets the check state of the list item to state.
Definition at line 105 of file qlistwidget.h.
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 656 of file qlistwidget.cpp.
void QListWidgetItem::setFlags | ( | Qt::ItemFlags | flags | ) |
Sets the item flags for the list item to flags.
Definition at line 961 of file qlistwidget.cpp.
Sets the font used when painting the item to the given font.
Definition at line 153 of file qlistwidget.h.
Sets the foreground brush of the list item to the given brush.
Setting a default-constructed brush will let the view use the default color from the style.
Definition at line 100 of file qlistwidget.h.
|
inline |
Hides the item if hide is true; otherwise shows the item.
Definition at line 272 of file qlistwidget.h.
Sets the icon for the list item to the given icon.
Definition at line 137 of file qlistwidget.h.
void QListWidgetItem::setSelected | ( | bool | select | ) |
Sets the selected state of the item to select.
Definition at line 919 of file qlistwidget.cpp.
Sets the size hint for the list item to be size.
If no size hint is set or size is invalid, the item delegate will compute the size hint based on the item data.
Definition at line 110 of file qlistwidget.h.
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 140 of file qlistwidget.h.
Sets the text for the list widget item's to the given text.
Definition at line 134 of file qlistwidget.h.
|
inline |
\obsolete [6.4] Use the overload that takes a Qt::Alignment argument.
Sets the list item's text alignment to alignment.
Sets the list item's text alignment to alignment.
Definition at line 90 of file qlistwidget.h.
|
inline |
Returns the size hint set for the list item.
Definition at line 108 of file qlistwidget.h.
|
inline |
Returns the list item's status tip.
Definition at line 56 of file qlistwidget.h.
|
inline |
|
inline |
Returns the text alignment for the list item.
Definition at line 80 of file qlistwidget.h.
|
inline |
Returns the type passed to the QListWidgetItem constructor.
Definition at line 124 of file qlistwidget.h.
|
virtual |
|
related |
Writes the list widget item item to stream out.
This operator uses QListWidgetItem::write().
Definition at line 778 of file qlistwidget.cpp.
|
related |
Reads a list widget item from stream in into item.
This operator uses QListWidgetItem::read().
Definition at line 793 of file qlistwidget.cpp.
|
friend |
Definition at line 24 of file qlistwidget.h.
|
friend |
Definition at line 25 of file qlistwidget.h.