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

QTreeWidgetItem Class

TheQTreeWidgetItem class provides an item for use with theQTreeWidget convenience class.More...

Header:#include <QTreeWidgetItem>

Public Types

enumChildIndicatorPolicy { ShowIndicator, DontShowIndicator, DontShowIndicatorWhenChildless }
enumItemType { Type, UserType }

Public Functions

QTreeWidgetItem(int type = Type)
QTreeWidgetItem(const QStringList & strings, int type = Type)
QTreeWidgetItem(QTreeWidget * parent, int type = Type)
QTreeWidgetItem(QTreeWidget * parent, const QStringList & strings, int type = Type)
QTreeWidgetItem(QTreeWidget * parent, QTreeWidgetItem * preceding, int type = Type)
QTreeWidgetItem(QTreeWidgetItem * parent, int type = Type)
QTreeWidgetItem(QTreeWidgetItem * parent, const QStringList & strings, int type = Type)
QTreeWidgetItem(QTreeWidgetItem * parent, QTreeWidgetItem * preceding, int type = Type)
QTreeWidgetItem(const QTreeWidgetItem & other)
virtual~QTreeWidgetItem()
voidaddChild(QTreeWidgetItem * child)
voidaddChildren(const QList<QTreeWidgetItem *> & children)
QBrushbackground(int column) const
Qt::CheckStatecheckState(int column) const
QTreeWidgetItem *child(int index) const
intchildCount() const
QTreeWidgetItem::ChildIndicatorPolicychildIndicatorPolicy() const
virtual QTreeWidgetItem *clone() const
intcolumnCount() const
virtual QVariantdata(int column, int role) const
Qt::ItemFlagsflags() const
QFontfont(int column) const
QBrushforeground(int column) const
QIconicon(int column) const
intindexOfChild(QTreeWidgetItem * child) const
voidinsertChild(int index, QTreeWidgetItem * child)
voidinsertChildren(int index, const QList<QTreeWidgetItem *> & children)
boolisDisabled() const
boolisExpanded() const
boolisFirstColumnSpanned() const
boolisHidden() const
boolisSelected() const
QTreeWidgetItem *parent() const
virtual voidread(QDataStream & in)
voidremoveChild(QTreeWidgetItem * child)
voidsetBackground(int column, const QBrush & brush)
voidsetCheckState(int column, Qt::CheckState state)
voidsetChildIndicatorPolicy(QTreeWidgetItem::ChildIndicatorPolicy policy)
virtual voidsetData(int column, int role, const QVariant & value)
voidsetDisabled(bool disabled)
voidsetExpanded(bool expand)
voidsetFirstColumnSpanned(bool span)
voidsetFlags(Qt::ItemFlags flags)
voidsetFont(int column, const QFont & font)
voidsetForeground(int column, const QBrush & brush)
voidsetHidden(bool hide)
voidsetIcon(int column, const QIcon & icon)
voidsetSelected(bool select)
voidsetSizeHint(int column, const QSize & size)
voidsetStatusTip(int column, const QString & statusTip)
voidsetText(int column, const QString & text)
voidsetTextAlignment(int column, int alignment)
voidsetToolTip(int column, const QString & toolTip)
voidsetWhatsThis(int column, const QString & whatsThis)
QSizesizeHint(int column) const
voidsortChildren(int column, Qt::SortOrder order)
QStringstatusTip(int column) const
QTreeWidgetItem *takeChild(int index)
QList<QTreeWidgetItem *>takeChildren()
QStringtext(int column) const
inttextAlignment(int column) const
QStringtoolTip(int column) const
QTreeWidget *treeWidget() const
inttype() const
QStringwhatsThis(int column) const
virtual voidwrite(QDataStream & out) const
virtual booloperator<(const QTreeWidgetItem & other) const
QTreeWidgetItem &operator=(const QTreeWidgetItem & other)

Protected Functions

Related Non-Members

QDataStream &operator<<(QDataStream & out, const QTreeWidgetItem & item)
QDataStream &operator>>(QDataStream & in, QTreeWidgetItem & item)

Detailed Description

TheQTreeWidgetItem class provides an item for use with theQTreeWidget convenience class.

Tree widget items are used to hold rows of information for tree widgets. Rows usually contain several columns of data, each of which can contain a text label and an icon.

TheQTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with theQTreeWidget class.

Items are usually constructed with a parent that is either aQTreeWidget (for top-level items) or aQTreeWidgetItem (for items on lower levels of the tree). For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:

QTreeWidgetItem*cities=newQTreeWidgetItem(treeWidget);    cities->setText(0, tr("Cities"));QTreeWidgetItem*osloItem=newQTreeWidgetItem(cities);    osloItem->setText(0, tr("Oslo"));    osloItem->setText(1, tr("Yes"));

Items can be added in a particular order by specifying the item they follow when they are constructed:

QTreeWidgetItem*planets=newQTreeWidgetItem(treeWidget, cities);    planets->setText(0, tr("Planets"));

Each column in an item can have its own background brush which is set with thesetBackground() function. The current background brush can be found withbackground(). The text label for each column can be rendered with its own font and brush. These are specified with thesetFont() andsetForeground() functions, and read withfont() andforeground().

The main difference between top-level items and those in lower levels of the tree is that a top-level item has noparent(). This information can be used to tell the difference between items, and is useful to know when inserting and removing items from the tree. Children of an item can be removed withtakeChild() and inserted at a given index in the list of children with theinsertChild() function.

By default, items are enabled, selectable, checkable, and can be the source of a drag and drop operation. Each item's flags can be changed by callingsetFlags() with the appropriate value (seeQt::ItemFlags). Checkable items can be checked and unchecked with thesetCheckState() function. The correspondingcheckState() function indicates whether the item is currently checked.

Subclassing

When subclassingQTreeWidgetItem to provide custom items, it is possible to define new types for them so that they can be distinguished from standard items. The constructors for subclasses that require this feature need to call the base class constructor with a new type value equal to or greater thanUserType.

See alsoQTreeWidget,QTreeWidgetItemIterator,Model/View Programming,QListWidgetItem, andQTableWidgetItem.

Member Type Documentation

enum QTreeWidgetItem::ChildIndicatorPolicy

ConstantValueDescription
QTreeWidgetItem::ShowIndicator0The controls for expanding and collapsing will be shown for this item even if there are no children.
QTreeWidgetItem::DontShowIndicator1The controls for expanding and collapsing will never be shown even if there are children. If the node is forced open the user will not be able to expand or collapse the item.
QTreeWidgetItem::DontShowIndicatorWhenChildless2The controls for expanding and collapsing will be shown if the item contains children.

This enum was introduced or modified in Qt 4.3.

enum QTreeWidgetItem::ItemType

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

ConstantValueDescription
QTreeWidgetItem::Type0The default type for tree widget items.
QTreeWidgetItem::UserType1000The minimum value for custom types. Values below UserType are reserved by Qt.

You can define new user types inQTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

See alsotype().

Member Function Documentation

QTreeWidgetItem::QTreeWidgetItem(int type = Type)

Constructs a tree widget item of the specifiedtype. The item must be inserted into a tree widget.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(constQStringList & strings,int type = Type)

Constructs a tree widget item of the specifiedtype. The item must be inserted into a tree widget. The given list ofstrings will be set as the item text for each column in the item.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(QTreeWidget * parent,int type = Type)

Constructs a tree widget item of the specifiedtype and appends it to the items in the givenparent.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(QTreeWidget * parent, constQStringList & strings,int type = Type)

Constructs a tree widget item of the specifiedtype and appends it to the items in the givenparent. The given list ofstrings will be set as the item text for each column in the item.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(QTreeWidget * parent,QTreeWidgetItem * preceding,int type = Type)

Constructs a tree widget item of the specifiedtype and inserts it into the givenparent after thepreceding item.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem * parent,int type = Type)

Constructs a tree widget item and append it to the givenparent.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem * parent, constQStringList & strings,int type = Type)

Constructs a tree widget item and append it to the givenparent. The given list ofstrings will be set as the item text for each column in the item.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem * parent,QTreeWidgetItem * preceding,int type = Type)

Constructs a tree widget item of the specifiedtype that is inserted into theparent after thepreceding child item.

See alsotype().

QTreeWidgetItem::QTreeWidgetItem(constQTreeWidgetItem & other)

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

This function is useful when reimplementingclone().

This function was introduced in Qt 4.1.

See alsodata() andflags().

[virtual]QTreeWidgetItem::~QTreeWidgetItem()

Destroys this tree widget item.

The item will be removed fromQTreeWidgets to which it has been added. This makes it safe to delete an item at any time.

void QTreeWidgetItem::addChild(QTreeWidgetItem * child)

Appends thechild item to the list of children.

See alsoinsertChild() andtakeChild().

void QTreeWidgetItem::addChildren(constQList<QTreeWidgetItem *> & children)

Appends the given list ofchildren to the item.

This function was introduced in Qt 4.1.

See alsoinsertChildren() andtakeChildren().

QBrush QTreeWidgetItem::background(int column) const

Returns the brush used to render the background of the specifiedcolumn.

This function was introduced in Qt 4.2.

See alsosetBackground() andforeground().

Qt::CheckState QTreeWidgetItem::checkState(int column) const

Returns the check state of the label in the givencolumn.

See alsosetCheckState() andQt::CheckState.

QTreeWidgetItem * QTreeWidgetItem::child(int index) const

Returns the item at the givenindex in the list of the item's children.

See alsoparent().

int QTreeWidgetItem::childCount() const

Returns the number of child items.

QTreeWidgetItem::ChildIndicatorPolicy QTreeWidgetItem::childIndicatorPolicy() const

Returns the item indicator policy. This policy decides when the tree branch expand/collapse indicator is shown.

See alsosetChildIndicatorPolicy().

[virtual]QTreeWidgetItem * QTreeWidgetItem::clone() const

Creates a deep copy of the item and of its children.

int QTreeWidgetItem::columnCount() const

Returns the number of columns in the item.

[virtual]QVariant QTreeWidgetItem::data(int column,int role) const

Returns the value for the item'scolumn androle.

See alsosetData().

[protected]void QTreeWidgetItem::emitDataChanged()

Causes the model associated with this item to emit adataChanged() signal for this item.

You normally only need to call this function if you have subclassedQTreeWidgetItem and reimplementeddata() and/orsetData().

This function was introduced in Qt 4.5.

See alsosetData().

Qt::ItemFlags QTreeWidgetItem::flags() const

Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.

The default value for flags isQt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled. If the item was constructed with a parent, flags will in addition containQt::ItemIsDropEnabled.

See alsosetFlags().

QFont QTreeWidgetItem::font(int column) const

Returns the font used to render the text in the specifiedcolumn.

See alsosetFont().

QBrush QTreeWidgetItem::foreground(int column) const

Returns the brush used to render the foreground (e.g. text) of the specifiedcolumn.

This function was introduced in Qt 4.2.

See alsosetForeground() andbackground().

QIcon QTreeWidgetItem::icon(int column) const

Returns the icon that is displayed in the specifiedcolumn.

See alsosetIcon() andiconSize.

int QTreeWidgetItem::indexOfChild(QTreeWidgetItem * child) const

Returns the index of the givenchild in the item's list of children.

void QTreeWidgetItem::insertChild(int index,QTreeWidgetItem * child)

Inserts thechild item atindex in the list of children.

If the child has already been inserted somewhere else it wont be inserted again.

void QTreeWidgetItem::insertChildren(int index, constQList<QTreeWidgetItem *> & children)

Inserts the given list ofchildren into the list of the item children atindex .

Children that have already been inserted somewhere else wont be inserted.

This function was introduced in Qt 4.1.

bool QTreeWidgetItem::isDisabled() const

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

This function was introduced in Qt 4.3.

See alsosetFlags().

bool QTreeWidgetItem::isExpanded() const

Returns true if the item is expanded, otherwise returns false.

This function was introduced in Qt 4.2.

See alsosetExpanded().

bool QTreeWidgetItem::isFirstColumnSpanned() const

Returns true if the item is spanning all the columns in a row; otherwise returns false.

This function was introduced in Qt 4.3.

See alsosetFirstColumnSpanned().

bool QTreeWidgetItem::isHidden() const

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

This function was introduced in Qt 4.2.

See alsosetHidden().

bool QTreeWidgetItem::isSelected() const

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

This function was introduced in Qt 4.2.

See alsosetSelected().

QTreeWidgetItem * QTreeWidgetItem::parent() const

Returns the item's parent.

See alsochild().

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

Reads the item from streamin. This only reads data into a single item.

See alsowrite().

void QTreeWidgetItem::removeChild(QTreeWidgetItem * child)

Removes the given item indicated bychild. The removed item will not be deleted.

void QTreeWidgetItem::setBackground(int column, constQBrush & brush)

Sets the background brush of the label in the givencolumn to the specifiedbrush.

This function was introduced in Qt 4.2.

See alsobackground() andsetForeground().

void QTreeWidgetItem::setCheckState(int column,Qt::CheckState state)

Sets the item in the givencolumn check state to bestate.

See alsocheckState().

void QTreeWidgetItem::setChildIndicatorPolicy(QTreeWidgetItem::ChildIndicatorPolicy policy)

Sets the item indicatorpolicy. This policy decides when the tree branch expand/collapse indicator is shown. The default value is ShowForChildren.

See alsochildIndicatorPolicy().

[virtual]void QTreeWidgetItem::setData(int column,int role, constQVariant & value)

Sets the value for the item'scolumn androle to the givenvalue.

Therole describes the type of data specified byvalue, and is defined by theQt::ItemDataRole enum.

See alsodata().

void QTreeWidgetItem::setDisabled(bool disabled)

Disables the item ifdisabled is true; otherwise enables the item.

This function was introduced in Qt 4.3.

See alsoisDisabled() andsetFlags().

void QTreeWidgetItem::setExpanded(bool expand)

Expands the item ifexpand is true, otherwise collapses the item.

Warning: TheQTreeWidgetItem must be added to theQTreeWidget before calling this function.

This function was introduced in Qt 4.2.

See alsoisExpanded().

void QTreeWidgetItem::setFirstColumnSpanned(bool span)

Sets the first section to span all columns ifspan is true; otherwise all item sections are shown.

This function was introduced in Qt 4.3.

See alsoisFirstColumnSpanned().

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

Sets the flags for the item to the givenflags. These determine whether the item can be selected or modified. This is often used to disable an item.

See alsoflags().

void QTreeWidgetItem::setFont(int column, constQFont & font)

Sets the font used to display the text in the givencolumn to the givenfont.

See alsofont(),setText(), andsetForeground().

void QTreeWidgetItem::setForeground(int column, constQBrush & brush)

Sets the foreground brush of the label in the givencolumn to the specifiedbrush.

This function was introduced in Qt 4.2.

See alsoforeground() andsetBackground().

void QTreeWidgetItem::setHidden(bool hide)

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

This function was introduced in Qt 4.2.

See alsoisHidden().

void QTreeWidgetItem::setIcon(int column, constQIcon & icon)

Sets the icon to be displayed in the givencolumn toicon.

See alsoicon(),setText(), andiconSize.

void QTreeWidgetItem::setSelected(bool select)

Sets the selected state of the item toselect.

This function was introduced in Qt 4.2.

See alsoisSelected().

void QTreeWidgetItem::setSizeHint(int column, constQSize & size)

Sets the size hint for the tree item in the givencolumn 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 QTreeWidgetItem::setStatusTip(int column, constQString & statusTip)

Sets the status tip for the givencolumn to the givenstatusTip.QTreeWidget mouse tracking needs to be enabled for this feature to work.

See alsostatusTip(),setToolTip(), andsetWhatsThis().

void QTreeWidgetItem::setText(int column, constQString & text)

Sets the text to be displayed in the givencolumn to the giventext.

See alsotext(),setFont(), andsetForeground().

void QTreeWidgetItem::setTextAlignment(int column,int alignment)

Sets the text alignment for the label in the givencolumn to thealignment specified (seeQt::AlignmentFlag).

See alsotextAlignment().

void QTreeWidgetItem::setToolTip(int column, constQString & toolTip)

Sets the tooltip for the givencolumn totoolTip.

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

void QTreeWidgetItem::setWhatsThis(int column, constQString & whatsThis)

Sets the "What's This?" help for the givencolumn towhatsThis.

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

QSize QTreeWidgetItem::sizeHint(int column) const

Returns the size hint set for the tree item in the givencolumn (seeQSize).

This function was introduced in Qt 4.1.

See alsosetSizeHint().

void QTreeWidgetItem::sortChildren(int column,Qt::SortOrder order)

Sorts the children of the item using the givenorder, by the values in the givencolumn.

Note:This function does nothing if the item is not associated with aQTreeWidget.

This function was introduced in Qt 4.2.

QString QTreeWidgetItem::statusTip(int column) const

Returns the status tip for the contents of the givencolumn.

See alsosetStatusTip().

QTreeWidgetItem * QTreeWidgetItem::takeChild(int index)

Removes the item atindex and returns it, otherwise return 0.

QList<QTreeWidgetItem *> QTreeWidgetItem::takeChildren()

Removes the list of children and returns it, otherwise returns an empty list.

This function was introduced in Qt 4.1.

QString QTreeWidgetItem::text(int column) const

Returns the text in the specifiedcolumn.

See alsosetText().

int QTreeWidgetItem::textAlignment(int column) const

Returns the text alignment for the label in the givencolumn (seeQt::AlignmentFlag).

See alsosetTextAlignment().

QString QTreeWidgetItem::toolTip(int column) const

Returns the tool tip for the givencolumn.

See alsosetToolTip().

QTreeWidget * QTreeWidgetItem::treeWidget() const

Returns the tree widget that contains the item.

int QTreeWidgetItem::type() const

Returns the type passed to theQTreeWidgetItem constructor.

QString QTreeWidgetItem::whatsThis(int column) const

Returns the "What's This?" help for the contents of the givencolumn.

See alsosetWhatsThis().

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

Writes the item to streamout. This only writes data from one single item.

See alsoread().

[virtual]bool QTreeWidgetItem::operator<(constQTreeWidgetItem & other) const

Returns true if the text in the item is less than the text in theother item, otherwise returns false.

QTreeWidgetItem & QTreeWidgetItem::operator=(constQTreeWidgetItem & other)

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

This function is useful when reimplementingclone().

See alsodata() andflags().

Related Non-Members

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

Writes the tree widget itemitem to streamout.

This operator usesQTreeWidgetItem::write().

See alsoSerializing Qt Data Types.

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

Reads a tree widget item from streamin intoitem.

This operator usesQTreeWidgetItem::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