[Qt-interest] Tree Item High Lighter
Andre Somers
andre at familiesomers.nl
Tue Dec 28 10:07:03 CET 2010
Op 27-12-2010 21:46, Sajjad schreef:
>
>
> On Mon, Dec 27, 2010 at 9:09 AM, André Somers <andre at familiesomers.nl
> <mailto:andre at familiesomers.nl>> wrote:
>
> 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.
>
>
>
> Is filtration and highlighting the same thing. I have going through
> some of the example and it shows that the the new filtered model based
> on the regular expression gets shrinked in the view. I do not want to
> alter the tree view except scrolling down to the particular item and
> highlight a particular item that matches the nearest expression.
No, sorry, it is not the same thing. However, you can still use
basically the same technique for it: a proxy model. Only, instead of
hiding items, you change their data. The data() method, as you may have
noticed, supports several roles. You can use the presentation-related
roles (background color, foreground color, font) for those nodes that
match your criteria, and return the normal, underlying data for all
other cases and roles.
>
>
> And the underlying data store does not support anything like what i
> am looking for. I have to implement in Qt. Do i have to implement
> this searching technique in the custimized QAbstractItemModel class?
Like I said before: I would probably not do that, unless it is needed
for performance reasons.
>
> While loading the database in the tree model i followed the example of
> simple tree model example in Qt Demo. If i have to implement this
> scenario in simple tree model, which class do i have to look into and
> specially which functions?
Well, proxy models are best based of QSortFilterProxyModel (even if you
don't plan to do any actual sorting or filtering), which is itself based
on QAbstractItemModel. So for returning data, you use the same methods
as you do with your real (data-containing) model. Use the mapFromSource
and mapToSource methods to map the model indexes between the proxy model
and the underlying data model and back.
Don't forget to emit the dataChanged() signal if you change the
highlighting criterium, otherwise your view won't know that you changed
the data and won't update.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101228/ba2eff1c/attachment.html
More information about the Qt-interest-old
mailing list