[Solved]Find a Child in a QTreeView
-
As it seems that you use a "QStandardItemModel":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html, have you tried "QStandardItemModel::findItems() ":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html#findItems already?
If you need more control you can call "QAbstractItemModel::match() ":http://doc.qt.nokia.com/4.7/qabstractitemmodel.html#match. The latter returns only a QModelIndexList, you will have to peek the items with "QStandardItemModel::itemFromIndex() ":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html#itemFromIndex then.
-
[quote author="gronerth" date="1301602957"]is QHash quicker?[/quote]
Possibly but it does not store the items in an ordered manner which is sometimes useful to have if you need to iterate over them in some specific order. Depends upon the exact use case you wish to cater for. -
[quote author="gronerth" date="1301605423"]Hi volker,
Well i have tried with findItems (and match), but the standarditemmodel only has the root items not the childs....I had to iterate just as Gerolf says...[/quote]
How do you create a hierarchy then? And what model do you use?
You can add Qt::MatchRecursive to the search flags of match and findItems.