PDA

View Full Version : Custom model and custom delegate



Higgs
7th April 2014, 14:53
Hi all!
I'm reading Johan Thelin's "Foundation of Qt Development" and my first big obstacle is understand model/view architecture. It seems a abit difficult for me. It confuses me.
Let's say I have table 4x4, I want to change background of (2,0). What can I do? Create custom delegate or custom model,right?
But which one to go? which is better?

wysota
7th April 2014, 15:09
If you want to change the background then how to do it depends on how your model is constructed. You can either teach your model to understand Qt::BackgroundRole so that the default delegate can ask for the background color and render it or you can implement a custom delegate that will know how to calculate the background color based on your model contents (or anything else that you want). In the latter case you will have to draw the background yourself.