[Qt-interest] how to traverse through QStandardItemModel

Andre Somers andre at familiesomers.nl
Tue Jun 22 11:38:27 CEST 2010


Op 21-6-2010 17:18, Valeriy Portnyagin schreef:
> hello all,
> I find the simple way for walking through all items in the 
> QStandardItemModel, in instance, like this:
>   - QList<QStandardItem*> model->getAllItems().
>   - QList<QModelIndex> model->getAllItems().
>
> I leant all function in this class but didn't find something convenient.
>  there is an example with QFileSystemModel:
>
> QFileSystemModel *model = new QFileSystemModel;
> QModelIndex parentIndex = model->index(QDir::currentPath());
> int numRows = model->rowCount(parentIndex);
> for (int row = 0; row < numRows; ++row) {
>         QModelIndex index = model->index(row, 0, parentIndex);
>         QString text = model->data(index, Qt::DisplayRole).toString();
>         // Display the text in a widget.
>      }
>
> I don't like such variant.
>
> So, how i understand i need my own function for the traverse my 
> QStandardItemModel or i have missed something?

Perhaps it *would* be nice to have a model iterator? Like you can create 
an iterator for another container, create one for a QAbstractItemModel. 
It could even have different strategies (depth-first, breadth-first, 
first-self-then-children, etc.) to determine the order in which to 
return the QModelIndex-es. Might be nice, and probably doable to make...

André

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100622/208c4bd3/attachment.html 


More information about the Qt-interest-old mailing list