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  · 

QListWidget Class Reference
[QtGui module]

The QListWidget class provides an item-based list widget. More...

#include <QListWidget>

Inherits QListView.

Properties

Public Functions

Public Slots

  • void clear ()
  • void scrollToItem ( const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible )

Signals

Protected Functions

  • virtual bool dropMimeData ( int index, const QMimeData * data, Qt::DropAction action )
  • QModelIndex indexFromItem ( QListWidgetItem * item ) const
  • QListWidgetItem * itemFromIndex ( const QModelIndex & index ) const
  • QList<QListWidgetItem *> items ( const QMimeData * data ) const
  • virtual QMimeData * mimeData ( const QList<QListWidgetItem *> items ) const
  • virtual QStringList mimeTypes () const
  • virtual Qt::DropActions supportedDropActions () const

Additional Inherited Members

  • 2 static public members inherited from QFrame
  • 4 static public members inherited from QWidget
  • 4 static public members inherited from QObject
  • 8 protected slots inherited from QAbstractItemView

Detailed Description

The QListWidget class provides an item-based list widget.

QListWidget is a convenience class that provides a list view similar to the one supplied by QListView, but with a classic item-based interface for adding and removing items. QListWidget uses an internal model to manage each QListWidgetItem in the list.

For a more flexible list view widget, use the QListView class with a standard model.

List widgets are constructed in the same way as other widgets:

        QListWidget *listWidget;

The selectionMode() of a list widget determines how many of the items in the list can be selected at the same time, and whether complex selections of items can be created. This can be set with the setSelectionMode() function.

There are two ways to add items to the list: they can be constructed with the list widget as their parent widget, or they can be constructed with no parent widget and added to the list later. If a list widget already exists when the items are constructed, the first method is easier to use:

        new QListWidgetItem(tr("Oak"), listWidget);
        new QListWidgetItem(tr("Fir"), listWidget);
        new QListWidgetItem(tr("Pine"), listWidget);

If you need to insert a new item into the list at a particular position, it is more convenient to construct the item without a parent widget and use the insertItem() function to place it within the list:

        QListWidgetItem *newItem = new QListWidgetItem;
        newItem->setText(itemText);
        listWidget->insertItem(row, newItem);

For multiple items, insertItems() can be used instead. The number of items in the list is found with the count() function. To remove items from the list, use takeItem().

The current item in the list can be found with currentItem(), and changed with setCurrentItem(). The user can also change the current item by navigating with the keyboard or clicking on a different item. When the current item changes, the currentItemChanged() signal is emitted with the new current item and the item that was previously current.

See also QListWidgetItem and Model/View Programming.


Property Documentation

count : const int

This property holds the number of items in the list including any hidden items.

Access functions:

  • int count () const

currentRow : int

This property holds the row of the current item.

Access functions:

  • int currentRow () const
  • void setCurrentRow ( int row )

Member Function Documentation

QListWidget::QListWidget ( QWidget * parent = 0 )

Constructs an empty QListWidget with the given parent.

QListWidget::~QListWidget ()

Destroys the list widget and all its items.

void QListWidget::addItem ( const QString & label )

Inserts an item with the text label at the end of the list widget.

void QListWidget::addItem ( QListWidgetItem * item )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts the item at the the end of the list widget.

See also insertItem().

void QListWidget::addItems ( const QStringList & labels )

Inserts items with the text labels at the end of the list widget.

See also insertItems().

void QListWidget::clear ()   [slot]

Removes all items and selections in the view.

void QListWidget::closePersistentEditor ( QListWidgetItem * item )

Closes the persistent editor for the given item.

See also openPersistentEditor().

QListWidgetItem * QListWidget::currentItem () const

Returns the current item.

See also setCurrentItem().

void QListWidget::currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous )   [signal]

This signal is emitted whenever the current item changes. The previous item is the item that previously had the focus, current is the new current item.

void QListWidget::currentRowChanged ( int currentRow )   [signal]

This signal is emitted whenever the current item changes. The currentRow is the row of the current item. If there is no current item, the currentRow is -1.

void QListWidget::currentTextChanged ( const QString & currentText )   [signal]

This signal is emitted whenever the current item changes. The currentText is the text data in the current item. If there is no current item, the currentText is invalid.

bool QListWidget::dropMimeData ( int index, const QMimeData * data, Qt::DropAction action )   [virtual protected]

Handles the data supplied by a drag and drop operation that ended with the given action in the given index.

See also supportedDropActions().

void QListWidget::editItem ( QListWidgetItem * item )

Starts editing the item if it is editable.

QList<QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const

Finds items with the text that matches the string text using the given flags.

QModelIndex QListWidget::indexFromItem ( QListWidgetItem * item ) const   [protected]

Returns the QModelIndex assocated with the given item.

void QListWidget::insertItem ( int row, QListWidgetItem * item )

Inserts the item at the position in the list given by row.

See also addItem().

void QListWidget::insertItem ( int row, const QString & label )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts an item with the text label in the list widget at the position given by row.

See also addItem().

void QListWidget::insertItems ( int row, const QStringList & labels )

Inserts items from the list of labels into the list, starting at the given row.

See also insertItem() and addItem().

bool QListWidget::isItemHidden ( const QListWidgetItem * item ) const

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

bool QListWidget::isItemSelected ( const QListWidgetItem * item ) const

Returns true if item is selected and not hidden; otherwise returns false.

QListWidgetItem * QListWidget::item ( int row ) const

Returns the item that occupies the given row in the list.

See also row().

void QListWidget::itemActivated ( QListWidgetItem * item )   [signal]

This signal is emitted when the item is activated. The item is activated when the user clicks or double clicks on it, depending on the system configuration. It is also activated when the user presses the activation key (on Windows and X11 this is the Return key, on Mac OS X it is Ctrl+0).

QListWidgetItem * QListWidget::itemAt ( const QPoint & p ) const

Returns a pointer to the item at the coordinates p.

QListWidgetItem * QListWidget::itemAt ( int x, int y ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns a pointer to the item at the coordinates (x, y).

void QListWidget::itemChanged ( QListWidgetItem * item )   [signal]

This signal is emitted whenever the data of item has changed.

void QListWidget::itemClicked ( QListWidgetItem * item )   [signal]

This signal is emitted when a mouse button is clicked. The item may be 0 if the mouse was not clicked on an item.

void QListWidget::itemDoubleClicked ( QListWidgetItem * item )   [signal]

This signal is emitted when a mouse button is double clicked. The item may be 0 if the mouse was not clicked on an item.

void QListWidget::itemEntered ( QListWidgetItem * item )   [signal]

This signal is emitted when the mouse cursor enters an item. The item is the item entered. This signal is only emitted when mouseTracking is turned on, or when a mouse button is pressed while moving into an item.

QListWidgetItem * QListWidget::itemFromIndex ( const QModelIndex & index ) const   [protected]

Returns a pointer to the QListWidgetItem assocated with the given index.

void QListWidget::itemPressed ( QListWidgetItem * item )   [signal]

This signal is emitted when a item has been pressed (mouse click and release). The item may be 0 if the mouse was not pressed on an item.

void QListWidget::itemSelectionChanged ()   [signal]

This signal is emitted whenever the selection changes.

See also selectedItems() and isItemSelected().

QList<QListWidgetItem *> QListWidget::items ( const QMimeData * data ) const   [protected]

Returns a list of pointers to the items contained in the data object. If the object was not created by a QListWidget in the same process, the list is empty.

QMimeData * QListWidget::mimeData ( const QList<QListWidgetItem *> items ) const   [virtual protected]

Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes() function.

If the list of items is empty, 0 is returned rather than a serialized empty list.

QStringList QListWidget::mimeTypes () const   [virtual protected]

Returns a list of MIME types that can be used to describe a list of listwidget items.

See also mimeData().

void QListWidget::openPersistentEditor ( QListWidgetItem * item )

Opens an editor for the given item. The editor remains open after editing.

See also closePersistentEditor().

int QListWidget::row ( const QListWidgetItem * item ) const

Returns the row containing the given item.

See also item().

void QListWidget::scrollToItem ( const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible )   [slot]

QList<QListWidgetItem *> QListWidget::selectedItems () const

Returns a list of all selected items in the list widget.

void QListWidget::setCurrentItem ( QListWidgetItem * item )

Sets the current item to item.

See also currentItem().

void QListWidget::setItemHidden ( const QListWidgetItem * item, bool hide )

If hide is true, the item will be hidden; otherwise it will be shown.

See also isItemHidden().

void QListWidget::setItemSelected ( const QListWidgetItem * item, bool select )

Selects or deselects the given item depending on whether select is true of false.

See also isItemSelected().

void QListWidget::sortItems ( Qt::SortOrder order = Qt::AscendingOrder )

Sorts all the items in the list widget according to the specified order.

Qt::DropActions QListWidget::supportedDropActions () const   [virtual protected]

Returns the drop actions supported by this view.

See also Qt::DropActions.

QListWidgetItem * QListWidget::takeItem ( int row )

Removes and returns the item from the given row in the list widget; otherwise returns 0.

Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.

See also insertItem() and addItem().

QRect QListWidget::visualItemRect ( const QListWidgetItem * item ) const

Returns the rectangle on the viewport occupied by the item at item.

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 103
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 56
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 93
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 32
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 231
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. 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.0
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