Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QTreeWidgetItem Class Reference
[QtGui module]

The QTreeWidgetItem class provides an item for use with the QTreeWidget convenience class. More...

 #include <QTreeWidgetItem>

Public Types

Public Functions

Related Non-Members

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

Detailed Description

The QTreeWidgetItem class provides an item for use with the QTreeWidget 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.

The QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with the QTreeWidget class.

Items are usually constructed with a parent that is either a QTreeWidget (for top-level items) or a QTreeWidgetItem (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 = new QTreeWidgetItem(treeWidget);
     cities->setText(0, tr("Cities"));
     QTreeWidgetItem *osloItem = new QTreeWidgetItem(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 = new QTreeWidgetItem(treeWidget, cities);
     planets->setText(0, tr("Planets"));

Each column in an item can have its own background brush which is set with the setBackground() function. The current background brush can be found with background(). The text label for each column can be rendered with its own font and brush. These are specified with the setFont() and setForeground() functions, and read with font() and foreground().

The main difference between top-level items and those in lower levels of the tree is that a top-level item has no parent(). 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 with takeChild() and inserted at a given index in the list of children with the insertChild() 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 calling setFlags() with the appropriate value (see Qt::ItemFlags). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.

Subclassing

When subclassing QTreeWidgetItem 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 than UserType.

See also QTreeWidget, Model/View Programming, QListWidgetItem, and QTableWidgetItem.


Member Type Documentation

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 in QTreeWidgetItem subclasses to ensure that custom items are treated specially; for example, when items are sorted.

See also type().


Member Function Documentation

QTreeWidgetItem::QTreeWidgetItem ( int type = Type )

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

See also type().

QTreeWidgetItem::QTreeWidgetItem ( const QStringList & strings, int type = Type )

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

See also type().

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

Constructs a tree widget item of the specified type and appends it to the items in the given parent.

See also type().

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

Constructs a tree widget item of the specified type and appends it to the items in the given parent. The given list of strings will be set as the item text for each column in the item.

See also type().

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

Constructs a tree widget item of the specified type and inserts it into the given parent after the preceding item.

See also type().

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

Constructs a tree widget item and append it to the given parent.

See also type().

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

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

See also type().

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

Constructs a tree widget item of the specified type that is inserted into the parent after the preceding child item.

See also type().

QTreeWidgetItem::QTreeWidgetItem ( const QTreeWidgetItem & other )

Constructs a copy of other. Note that type() and treeWidget() are not copied.

This function is useful when reimplementing clone().

This function was introduced in Qt 4.1.

See also data() and flags().

QTreeWidgetItem::~QTreeWidgetItem ()   [virtual]

Destroys this tree widget item.

void QTreeWidgetItem::addChild ( QTreeWidgetItem * child )

Appends the child item to the list of children.

See also insertChild() and takeChild().

void QTreeWidgetItem::addChildren ( const QList<QTreeWidgetItem *> & children )

Appends the given list of children to the item.

This function was introduced in Qt 4.1.

See also insertChildren() and takeChildren().

QBrush QTreeWidgetItem::background ( int column ) const

Returns the brush used to render the background of the specified column.

This function was introduced in Qt 4.2.

See also setBackground() and foreground().

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

Returns the check state of the label in the given column.

See also setCheckState() and Qt::CheckState.

QTreeWidgetItem * QTreeWidgetItem::child ( int index ) const

Returns the item at the given index in the list of the item's children.

See also parent().

int QTreeWidgetItem::childCount () const

Returns the number of child items.

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

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

int QTreeWidgetItem::columnCount () const

Returns the number of columns in the item.

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

Returns the value for the item's column and role.

See also setData().

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 is Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled. If the item was constructed with a parent, flags will in addition contain Qt::ItemIsDropEnabled.

See also setFlags().

QFont QTreeWidgetItem::font ( int column ) const

Returns the font used to render the text in the specified column.

See also setFont().

QBrush QTreeWidgetItem::foreground ( int column ) const

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

This function was introduced in Qt 4.2.

See also setForeground() and background().

QIcon QTreeWidgetItem::icon ( int column ) const

Returns the icon that is displayed in the specified column.

See also setIcon() and iconSize.

int QTreeWidgetItem::indexOfChild ( QTreeWidgetItem * child ) const

Returns the index of the given child in the item's list of children.

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

Inserts the child item at index in the list of children.

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

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

Inserts the given list of children into the list of the item children at index .

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

This function was introduced in Qt 4.1.

bool QTreeWidgetItem::isExpanded () const

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

This function was introduced in Qt 4.2.

See also setExpanded().

bool QTreeWidgetItem::isHidden () const

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

This function was introduced in Qt 4.2.

See also setHidden().

bool QTreeWidgetItem::isSelected () const

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

This function was introduced in Qt 4.2.

See also setSelected().

QTreeWidgetItem * QTreeWidgetItem::parent () const

Returns the item's parent.

See also child().

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

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

See also write().

void QTreeWidgetItem::setBackground ( int column, const QBrush & brush )

Sets the background brush of the label in the given column to the specified brush.

This function was introduced in Qt 4.2.

See also background() and setForeground().

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

Sets the item in the given column check state to be state.

See also checkState().

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

Sets the value for the item's column and role to the given value.

The role describes the type of data specified by value, and is defined by the Qt::ItemDataRole enum.

See also data().

void QTreeWidgetItem::setExpanded ( bool expand )

Expands the item if expand is true, otherwise collapses the item.

This function was introduced in Qt 4.2.

See also isExpanded().

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

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

See also flags().

void QTreeWidgetItem::setFont ( int column, const QFont & font )

Sets the font used to display the text in the given column to the given font.

See also font(), setText(), and setForeground().

void QTreeWidgetItem::setForeground ( int column, const QBrush & brush )

Sets the foreground brush of the label in the given column to the specified brush.

This function was introduced in Qt 4.2.

See also foreground() and setBackground().

void QTreeWidgetItem::setHidden ( bool hide )

Hides the item if hide is true, otherwise shows the item.

This function was introduced in Qt 4.2.

See also isHidden().

void QTreeWidgetItem::setIcon ( int column, const QIcon & icon )

Sets the icon to be displayed in the given column to icon.

See also icon(), setText(), and iconSize.

void QTreeWidgetItem::setSelected ( bool select )

Sets the selected state of the item to select.

This function was introduced in Qt 4.2.

See also isSelected().

void QTreeWidgetItem::setSizeHint ( int column, const QSize & size )

Sets the size hint for the tree item in the given column to be size. 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 also sizeHint().

void QTreeWidgetItem::setStatusTip ( int column, const QString & statusTip )

Sets the status tip for the given column to the given statusTip. QTreeWidget mouse tracking needs to be enabled for this feature to work.

See also statusTip(), setToolTip(), and setWhatsThis().

void QTreeWidgetItem::setText ( int column, const QString & text )

Sets the text to be displayed in the given column to the given text.

See also text(), setFont(), and setForeground().

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

Sets the text alignment for the label in the given column to the alignment specified (see Qt::AlignmentFlag).

See also textAlignment().

void QTreeWidgetItem::setToolTip ( int column, const QString & toolTip )

Sets the tooltip for the given column to toolTip.

See also toolTip(), setStatusTip(), and setWhatsThis().

void QTreeWidgetItem::setWhatsThis ( int column, const QString & whatsThis )

Sets the "What's This?" help for the given column to whatsThis.

See also whatsThis(), setStatusTip(), and setToolTip().

QSize QTreeWidgetItem::sizeHint ( int column ) const

Returns the size hint set for the tree item in the given column (see QSize).

This function was introduced in Qt 4.1.

See also setSizeHint().

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

Sorts the children of the item using the given order, by the values in the given column.

This function was introduced in Qt 4.2.

QString QTreeWidgetItem::statusTip ( int column ) const

Returns the status tip for the contents of the given column.

See also setStatusTip().

QTreeWidgetItem * QTreeWidgetItem::takeChild ( int index )

Removes the item at index and returns it, otherwise return 0.

QList<QTreeWidgetItem *> QTreeWidgetItem::takeChildren ()

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

This function was introduced in Qt 4.1.

QString QTreeWidgetItem::text ( int column ) const

Returns the text in the specified column.

See also setText().

int QTreeWidgetItem::textAlignment ( int column ) const

Returns the text alignment for the label in the given column (see Qt::AlignmentFlag).

See also setTextAlignment().

QString QTreeWidgetItem::toolTip ( int column ) const

Returns the tool tip for the given column.

See also setToolTip().

QTreeWidget * QTreeWidgetItem::treeWidget () const

Returns the tree widget that contains the item.

int QTreeWidgetItem::type () const

Returns the type passed to the QTreeWidgetItem constructor.

QString QTreeWidgetItem::whatsThis ( int column ) const

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

See also setWhatsThis().

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

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

See also read().

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

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

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

Assigns other's data and flags to this item. Note that type() and treeWidget() are not copied.

This function is useful when reimplementing clone().

See also data() and flags().


Related Non-Members

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

This is an overloaded member function, provided for convenience.

Writes the tree widget item item to stream out.

This operator uses QTreeWidgetItem::write().

See also Format of the QDataStream Operators.

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

This is an overloaded member function, provided for convenience.

Reads a tree widget item from stream in into item.

This operator uses QTreeWidgetItem::read().

See also Format of the QDataStream Operators.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 59
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Labs au hasard

Logo

Construire l'avenir : (ré-)introduction aux composants de Qt Quick

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web