PDA

View Full Version : Models, Views, and Styling



Goug
29th November 2011, 21:56
I'm really struggling with some of the model/view structures in Qt. In particular, I don't understand why the model is controlling the appearance. The "data" method returns visual styling information for the various roles, which means that all of the views on that model share the same presentation, which makes no sense if the purpose of the model and view separation is to isolate the model from its presentation.

When I started looking into QStyledItemDelegate, I thought it was the answer to my problem. I understand that I can use it to take over the drawing, but I don't want or need to completely handle the painting. I just need to set colors and fonts for the roles (exactly as the model is doing, but independently of the model). I don't see how to do that using a delegate unless I also draw every item myself.

This is driving me nuts. Am I missing something?

Doug

d_stranz
29th November 2011, 22:29
You could use a view-specific QAbstractProxyModel between the real model and the view to basically override the presentation role values that are being returned by the real model. Override the data() method to either return your own presentation setting or call the wrapped model's own data() method where desired.

Goug
2nd December 2011, 04:29
The proxy model ended up working out pretty well for the presentation. It eliminates the concerns I had, and since I'll need sorting and/or filtering, it makes sense to include it now.

Thanks,
Doug