Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QListWidgetItem Class

TheQListWidgetItem class provides an item for use with theQListWidget item view class.More...

Header:#include <QListWidgetItem>

Public Types

enumItemType { Type, UserType }

Public Functions

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()
QBrushbackground() const
Qt::CheckStatecheckState() const
virtual QListWidgetItem *clone() const
virtual QVariantdata(int role) const
Qt::ItemFlagsflags() const
QFontfont() const
QBrushforeground() const
QIconicon() const
boolisHidden() const
boolisSelected() const
QListWidget *listWidget() const
virtual voidread(QDataStream & in)
voidsetBackground(const QBrush & brush)
voidsetCheckState(Qt::CheckState state)
virtual voidsetData(int role, const QVariant & value)
voidsetFlags(Qt::ItemFlags flags)
voidsetFont(const QFont & font)
voidsetForeground(const QBrush & brush)
voidsetHidden(bool hide)
voidsetIcon(const QIcon & icon)
voidsetSelected(bool select)
voidsetSizeHint(const QSize & size)
voidsetStatusTip(const QString & statusTip)
voidsetText(const QString & text)
voidsetTextAlignment(int alignment)
voidsetToolTip(const QString & toolTip)
voidsetWhatsThis(const QString & whatsThis)
QSizesizeHint() const
QStringstatusTip() const
QStringtext() const
inttextAlignment() const
QStringtoolTip() const
inttype() const
QStringwhatsThis() const
virtual voidwrite(QDataStream & out) const
virtual booloperator<(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

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

Subclassing

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.

Member Type Documentation

enum QListWidgetItem::ItemType

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

ConstantValueDescription
QListWidgetItem::Type0The default type for list widget items.
QListWidgetItem::UserType1000The 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().

Member Function Documentation

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

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

QListWidgetItem::QListWidgetItem(constQString & text,QListWidget * parent = 0,int type = Type)

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

QListWidgetItem::QListWidgetItem(constQIcon & icon, constQString & text,QListWidget * parent = 0,int type = Type)

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

QListWidgetItem::QListWidgetItem(constQListWidgetItem & other)

Constructs a copy ofother. Note thattype() andlistWidget() are not copied.

This function is useful when reimplementingclone().

This function was introduced in Qt 4.1.

See alsodata() andflags().

[virtual]QListWidgetItem::~QListWidgetItem()

Destroys the list item.

QBrush QListWidgetItem::background() const

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

This function was introduced in Qt 4.2.

See alsosetBackground() andforeground().

Qt::CheckState QListWidgetItem::checkState() const

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

See alsosetCheckState() andflags().

[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 givenrole. Reimplement this function if you need extra roles or special behavior for certain roles.

See alsoQt::ItemDataRole andsetData().

Qt::ItemFlags QListWidgetItem::flags() const

Returns the item flags for this item (seeQt::ItemFlags).

See alsosetFlags().

QFont QListWidgetItem::font() const

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

See alsosetFont().

QBrush QListWidgetItem::foreground() const

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

QIcon QListWidgetItem::icon() const

Returns the list item's icon.

See alsosetIcon() andiconSize.

bool QListWidgetItem::isHidden() const

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

This function was introduced in Qt 4.2.

See alsosetHidden().

bool QListWidgetItem::isSelected() const

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

This function was introduced in Qt 4.2.

See alsosetSelected().

QListWidget * QListWidgetItem::listWidget() const

Returns the list widget containing the item.

[virtual]void QListWidgetItem::read(QDataStream & in)

Reads the item from streamin.

See alsowrite().

void QListWidgetItem::setBackground(constQBrush & brush)

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

This function was introduced in Qt 4.2.

See alsobackground() andsetForeground().

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

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

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

Sets the item flags for the list item toflags.

See alsoflags() andQt::ItemFlags.

void QListWidgetItem::setFont(constQFont & font)

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

See alsofont().

void QListWidgetItem::setForeground(constQBrush & brush)

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

This function was introduced in Qt 4.2.

See alsoforeground() andsetBackground().

void QListWidgetItem::setHidden(bool hide)

Hides the item ifhide is true; otherwise shows the item.

This function was introduced in Qt 4.2.

See alsoisHidden().

void QListWidgetItem::setIcon(constQIcon & icon)

Sets the icon for the list item to the givenicon.

See alsoicon(),text(), andiconSize.

void QListWidgetItem::setSelected(bool select)

Sets the selected state of the item toselect.

This function was introduced in Qt 4.2.

See alsoisSelected().

void QListWidgetItem::setSizeHint(constQSize & size)

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

void QListWidgetItem::setStatusTip(constQString & statusTip)

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

void QListWidgetItem::setText(constQString & text)

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

See alsotext().

void QListWidgetItem::setTextAlignment(int alignment)

Sets the list item's text alignment toalignment.

See alsotextAlignment() andQt::AlignmentFlag.

void QListWidgetItem::setToolTip(constQString & toolTip)

Sets the tooltip for the list item to the text specified bytoolTip.

See alsotoolTip(),setStatusTip(), andsetWhatsThis().

void QListWidgetItem::setWhatsThis(constQString & whatsThis)

Sets the "What's This?" help for the list item to the text specified bywhatsThis.

See alsowhatsThis(),setStatusTip(), andsetToolTip().

QSize QListWidgetItem::sizeHint() const

Returns the size hint set for the list item.

This function was introduced in Qt 4.1.

See alsosetSizeHint().

QString QListWidgetItem::statusTip() const

Returns the list item's status tip.

See alsosetStatusTip().

QString QListWidgetItem::text() const

Returns the list item's text.

See alsosetText().

int QListWidgetItem::textAlignment() const

Returns the text alignment for the list item.

See alsosetTextAlignment() andQt::AlignmentFlag.

QString QListWidgetItem::toolTip() const

Returns the list item's tooltip.

See alsosetToolTip(),statusTip(), andwhatsThis().

int QListWidgetItem::type() const

Returns the type passed to theQListWidgetItem constructor.

QString QListWidgetItem::whatsThis() const

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

See alsosetWhatsThis(),statusTip(), andtoolTip().

[virtual]void QListWidgetItem::write(QDataStream & out) const

Writes the item to streamout.

See alsoread().

[virtual]bool QListWidgetItem::operator<(constQListWidgetItem & other) const

Returns true if this item's text is less thenother item's text; otherwise returns false.

QListWidgetItem & QListWidgetItem::operator=(constQListWidgetItem & other)

Assignsother's data and flags to this item. Note thattype() andlistWidget() are not copied.

This function is useful when reimplementingclone().

See alsodata() andflags().

Related Non-Members

QDataStream &operator<<(QDataStream & out, constQListWidgetItem & item)

Writes the list widget itemitem to streamout.

This operator usesQListWidgetItem::write().

See alsoSerializing Qt Data Types.

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

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.


[8]ページ先頭

©2009-2025 Movatter.jp