[Qt-interest] item delegates
Andre Somers
andre at familiesomers.nl
Wed Mar 9 17:38:54 CET 2011
Op 9-3-2011 12:52, Graham Labdon schreef:
>
> Hi
>
> I am implementing a Item Delegate for my tree based model.
>
> I need to create a different editor depending upon the item being edited.
>
> At the moment I am using switch statements to decide which editor to
> supply, but as my model grows so do the switch statements.
>
> (...)
>
> Is there a better way to achieve this?
>
Sure there is.
What you are currently doing, is hardcoding the editor to use for each
of your cells. That isn't very flexible, and as you noticed, it gets you
in trouble with huge, unmaintainable switch statements or if/else cascades.
What I would suggest, is to use a custom role in your data model that
you can use to decide on the editor to use. That way, you end up with a
way more flexible solution.
You might also look into an existing property editor solution, as that
seems to be what you are making. It depends on how your actual data is
organized of course, but I am using one based on Qt's meta object system
(extended version of YAPE), and that works nicely.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110309/cfa3ae61/attachment.html
More information about the Qt-interest-old
mailing list