QListWidgetItem Class
The QListWidgetItem class provides an item for use with the QListWidget item view class. More...
Header: | #include <QListWidgetItem> |
qmake: | QT += widgets |
Public Types
enum | ItemType { Type, UserType } |
Public Functions
QListWidgetItem(QListWidget *view = nullptr, int type = Type) | |
QListWidgetItem(const QString &text, QListWidget *view = nullptr, int type = Type) | |
QListWidgetItem(const QIcon &icon, const QString &text, QListWidget *view = nullptr, int type = Type) | |
QListWidgetItem(const QListWidgetItem &other) | |
virtual | ~QListWidgetItem() |
QBrush | background() const |
QColor | backgroundColor() 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) |
virtual void | setBackgroundColor(const QColor &color) |
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 | setTextColor(const QColor &color) |
void | setToolTip(const QString &toolTip) |
void | setWhatsThis(const QString &whatsThis) |
QSize | sizeHint() const |
QString | statusTip() const |
QString | text() const |
int | textAlignment() const |
QColor | textColor() 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) |
Related Non-Members
QDataStream & | operator<<(QDataStream &out, const QListWidgetItem &item) |
QDataStream & | operator>>(QDataStream &in, QListWidgetItem &item) |
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, and QTableWidgetItem.
Member Type Documentation
enum QListWidgetItem::ItemType
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 in QListWidgetItem subclasses to ensure that custom items are treated specially.
See also type().
Member Function Documentation
QListWidgetItem::QListWidgetItem(QListWidget *view = nullptr, int type = Type)
Default constructs an instance of QListWidgetItem.
QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *view = nullptr, int type = Type)
Default constructs an instance of QListWidgetItem.
QListWidgetItem::QListWidgetItem(const QIcon &icon, const QString &text, QListWidget *view = nullptr, int type = Type)
Default constructs an instance of QListWidgetItem.
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().
This function was introduced in Qt 4.1.
[virtual]
QListWidgetItem::~QListWidgetItem()
Destroys the list item.
QBrush QListWidgetItem::background() const
See also setBackground().
QColor QListWidgetItem::backgroundColor() const
See also setBackgroundColor().
Qt::CheckState QListWidgetItem::checkState() const
See also setCheckState().
[virtual]
QListWidgetItem *QListWidgetItem::clone() const
Creates an exact copy of the item.
[virtual]
QVariant QListWidgetItem::data(int role) const
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().
Qt::ItemFlags QListWidgetItem::flags() const
See also setFlags().
QFont QListWidgetItem::font() const
See also setFont().
QBrush QListWidgetItem::foreground() const
See also setForeground().
QIcon QListWidgetItem::icon() const
See also setIcon().
bool QListWidgetItem::isHidden() const
bool QListWidgetItem::isSelected() const
QListWidget *QListWidgetItem::listWidget() const
[virtual]
void QListWidgetItem::read(QDataStream &in)
Reads the item from stream in.
See also write().
void QListWidgetItem::setBackground(const QBrush &brush)
See also background().
[virtual]
void QListWidgetItem::setBackgroundColor(const QColor &color)
See also backgroundColor().
void QListWidgetItem::setCheckState(Qt::CheckState state)
See also checkState().
[virtual]
void QListWidgetItem::setData(int role, const QVariant &value)
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.
Note: The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data.
See also Qt::ItemDataRole and data().
void QListWidgetItem::setFlags(Qt::ItemFlags flags)
See also flags().
void QListWidgetItem::setFont(const QFont &font)
See also font().
void QListWidgetItem::setForeground(const QBrush &brush)
See also foreground().
void QListWidgetItem::setHidden(bool hide)
See also isHidden().
void QListWidgetItem::setIcon(const QIcon &icon)
See also icon().
void QListWidgetItem::setSelected(bool select)
See also isSelected().
void QListWidgetItem::setSizeHint(const QSize &size)
See also sizeHint().
void QListWidgetItem::setStatusTip(const QString &statusTip)
See also statusTip().
void QListWidgetItem::setText(const QString &text)
See also text().
void QListWidgetItem::setTextAlignment(int alignment)
See also textAlignment().
void QListWidgetItem::setTextColor(const QColor &color)
See also textColor().
void QListWidgetItem::setToolTip(const QString &toolTip)
See also toolTip().
void QListWidgetItem::setWhatsThis(const QString &whatsThis)
See also whatsThis().
QSize QListWidgetItem::sizeHint() const
See also setSizeHint().
QString QListWidgetItem::statusTip() const
See also setStatusTip().
QString QListWidgetItem::text() const
See also setText().
int QListWidgetItem::textAlignment() const
See also setTextAlignment().
QColor QListWidgetItem::textColor() const
See also setTextColor().
QString QListWidgetItem::toolTip() const
See also setToolTip().
int QListWidgetItem::type() const
QString QListWidgetItem::whatsThis() const
See also setWhatsThis().
[virtual]
void QListWidgetItem::write(QDataStream &out) const
Writes the item to stream out.
See also read().
[virtual]
bool QListWidgetItem::operator<(const QListWidgetItem &other) const
Returns true
if this item's text is less then other item's text; otherwise returns false
.
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().
Related Non-Members
QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item)
Writes the list widget item item to stream out.
This operator uses QListWidgetItem::write().
See also Serializing Qt Data Types.
QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
Reads a list widget item from stream in into item.
This operator uses QListWidgetItem::read().
See also Serializing Qt Data Types.