PDA

View Full Version : MVC Questions



ComaWhite
14th March 2009, 02:24
I need to write a QTreeView which will store an icon based that is their default an a icon when they are away and will have like other icons too. And also will have 2 colours based on what the user sets in the options menu.

Right now I have a NickDelegate (QStyledItemDelegate) and a NickTree(QTreeView). Well so far the NickDelegate handles the text colour changing based on away and online. This is the other part that confuses me with MVC. Is where do I return the icons? Since pretty much a delegate, view, and model can all handle it (correct me if I'm wrong) has the ability. Which one do I put it.

And how do I handle custom roles?

aamer4yu
14th March 2009, 05:31
The base for data is the Model. You need to provide your data from the model.
The view arranges how data should be displayed, and asks the delegate to draw for it.

Delegates are helpful when you want to keep your model intact and provide some modified drawing. For example you return a icon from model. In delegate you see if user is online/offline and generate a pixmap for online/offline and render it. Also you could pass online/offline icons from model also.

Keeping the data in model helps that you dont write your own delegate. Qt provides default delegates, and if your model is well populated, it will do the drawing. Only where you want to cross the limit the default delegate provides, write your own .