[Qt-interest] Tree Item High Lighter

André Somers andre at familiesomers.nl
Mon Dec 27 09:09:34 CET 2010


I would look into QSortFilterProxyModel instead. You don't have to change your base tree model at all that way. Of course, if your underlying data store supports efficient searching (based on indexes for instance), then it would be better to implement the capability in your base model. 

Note that by default, the proxy model only filters based on the root nodes. It is possible to customize it so it will include a node if one of it's child nodes match, but that requires some coding and will require an (almost) complete traversal of your tree. That makes it slow on big trees. 

André

Op 27 dec. 2010 om 04:52 heeft Eckhard Jokisch <e.jokisch at orange-moon.de> het volgende geschreven:

> Am 27.12.2010 00:54, schrieb Sajjad:
>> Hello forum,
>> 
>> I have subclassed the QAbstractItemModel to generate a customized tree model
>> and since the tree model represent a large database, it is hard for the user
>> to browse down all  the items in the  tree and find a  particular item. For
>> a better usability, i would like to have a textfield where the user type a
>> item name and the item with the name matched will be highlighted in the
>> tree.
>> 
>> Any hint on implementing this feature. I think i need to work with regular
>> expression here and i am not sure how to search down the tree and highlight
>> it.
> What about this:
> while setting up the model data also fill a QHash<QString,QModelIndex>.
> Like this you can simply search for the string in the QHash and get the
> associated modelindex.
> 
> Have fun
> 
> Eckhard
> 
>> 
>> If there is already any example implementing this feature, please forward me
>> to this.
>> 
>> 
>> Any suggestion on implementing this feature would be very helpful.
>> 
>> 
>> Happy New Year
>> 
>> Sajjad
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list