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  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QStringListModel Class Reference

The QStringListModel class provides a model that supplies strings to views. More...

 #include <QStringListModel>

Inherits: QAbstractListModel.

Inherited by: QHelpIndexModel.

Public Functions

QStringListModel ( QObject * parent = 0 )
QStringListModel ( const QStringList & strings, QObject * parent = 0 )
void setStringList ( const QStringList & strings )
QStringList stringList () const

Reimplemented Public Functions

virtual QVariant data ( const QModelIndex & index, int role ) const
virtual Qt::ItemFlags flags ( const QModelIndex & index ) const
virtual bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() )
virtual bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() )
virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const
virtual bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )
virtual void sort ( int column, Qt::SortOrder order = Qt::AscendingOrder )
virtual Qt::DropActions supportedDropActions () const

Additional Inherited Members

Detailed Description

The QStringListModel class provides a model that supplies strings to views.

QStringListModel is an editable model that can be used for simple cases where you need to display a number of strings in a view widget, such as a QListView or a QComboBox.

The model provides all the standard functions of an editable model, representing the data in the string list as a model with one column and a number of rows equal to the number of items in the list.

Model indexes corresponding to items are obtained with the index() function, and item flags are obtained with flags(). Item data is read with the data() function and written with setData(). The number of rows (and number of items in the string list) can be found with the rowCount() function.

The model can be constructed with an existing string list, or strings can be set later with the setStringList() convenience function. Strings can also be inserted in the usual way with the insertRows() function, and removed with removeRows(). The contents of the string list can be retrieved with the stringList() convenience function.

An example usage of QStringListModel:

     QStringListModel *model = new QStringListModel();
     QStringList list;
     list << "a" << "b" << "c";
     model->setStringList(list);

See also QAbstractListModel, QAbstractItemModel, and Model Classes.

Member Function Documentation

QStringListModel::QStringListModel ( QObject * parent = 0 )

Constructs a string list model with the given parent.

QStringListModel::QStringListModel ( const QStringList & strings, QObject * parent = 0 )

Constructs a string list model containing the specified strings with the given parent.

QVariant QStringListModel::data ( const QModelIndex & index, int role ) const [virtual]

Reimplemented from QAbstractItemModel::data().

Returns data for the specified role, from the item with the given index.

If the view requests an invalid index, an invalid variant is returned.

See also setData().

Qt::ItemFlags QStringListModel::flags ( const QModelIndex & index ) const [virtual]

Reimplemented from QAbstractItemModel::flags().

Returns the flags for the item with the given index.

Valid items are enabled, selectable, editable, drag enabled and drop enabled.

See also QAbstractItemModel::flags().

bool QStringListModel::insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() ) [virtual]

Reimplemented from QAbstractItemModel::insertRows().

Inserts count rows into the model, beginning at the given row.

The parent index of the rows is optional and is only used for consistency with QAbstractItemModel. By default, a null index is specified, indicating that the rows are inserted in the top level of the model.

See also QAbstractItemModel::insertRows().

bool QStringListModel::removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() ) [virtual]

Reimplemented from QAbstractItemModel::removeRows().

Removes count rows from the model, beginning at the given row.

The parent index of the rows is optional and is only used for consistency with QAbstractItemModel. By default, a null index is specified, indicating that the rows are removed in the top level of the model.

See also QAbstractItemModel::removeRows().

int QStringListModel::rowCount ( const QModelIndex & parent = QModelIndex() ) const [virtual]

Reimplemented from QAbstractItemModel::rowCount().

Returns the number of rows in the model. This value corresponds to the number of items in the model's internal string list.

The optional parent argument is in most models used to specify the parent of the rows to be counted. Because this is a list if a valid parent is specified, the result will always be 0.

See also insertRows(), removeRows(), and QAbstractItemModel::rowCount().

bool QStringListModel::setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) [virtual]

Reimplemented from QAbstractItemModel::setData().

Sets the data for the specified role in the item with the given index in the model, to the provided value.

The dataChanged() signal is emitted if the item is changed.

See also Qt::ItemDataRole and data().

void QStringListModel::setStringList ( const QStringList & strings )

Sets the model's internal string list to strings. The model will notify any attached views that its underlying data has changed.

See also stringList() and dataChanged().

void QStringListModel::sort ( int column, Qt::SortOrder order = Qt::AscendingOrder ) [virtual]

Reimplemented from QAbstractItemModel::sort().

QStringList QStringListModel::stringList () const

Returns the string list used by the model to store data.

See also setStringList().

Qt::DropActions QStringListModel::supportedDropActions () const [virtual]

Reimplemented from QAbstractItemModel::supportedDropActions().

Publicit�

Best Of

Actualit�s les plus lues

Semaine
Mois
Ann�e
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la sp�cification pour la conception d'applications parall�les C++ utilisant le GPU 22
  2. Les d�veloppeurs ignorent-ils trop les failles d�couvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : � 13 % des d�veloppeurs ont gagn� plus de 100 000 $ sur l'AppWord �, Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. � Quelque chose ne va vraiment pas avec les d�veloppeurs "modernes" �, un d�veloppeur � "l'ancienne" critique la multiplication des biblioth�ques 12
  5. 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
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil d�claratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveaut�s de C++11 Visual C++ doit-il rapidement int�grer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

Le Qt Developer Network est un r�seau de d�veloppeurs Qt anglophone, o� ils peuvent partager leur exp�rience sur le framework. 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.7
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