First, thanks Nokia for providing such a tool.
Nevertheless, few things are bugging me.
In your model/view classes, your model class(es) have to provide the view some clues about how the data should be displayed, by the "role" parameter (ForegroudRole, BackgroundColorRole etc...), which defies the very principle of the model/view pattern !! I mean that these considerations should be left to the view class (just think about what is actually stored, in mysql tables, you rarely put the color or alignment of rows or columns). Moreover, by doing so, you make it very clumsy to change such a basic parameter as a default textalignment for items, color for a specific item etc... For example, to my knowledge, the only way to change textalignment is to subclass a model and reimpliment data, while this should be set not even programmaticly but in QtDesigner.
Why not create a default viewclass with enough parameters to make it useless to subclass it ? The viewclass would have a default format option for all columns and would provide functions to change it for a specific column, or even cell.
Looking forward for the next release though !
Did you discover the concept of Delegates yet in the framework? They do all the rendering. You don't have to use the roles to control how your item is rendered.
Note that your proposed view class would break the model/view concept in an even worse way. I mean: giving the view methods to change the formatting of a single cell? That's rediculous. How would that work if the data in the model is not fixed?
I do agree that it is too complicated to style items according to some criteria like the row, the column, the value or some other role. I have attempted to create a delegate to work around that, and came a long way, but the remaining issue was the rendering of the styled cell in the end. The way that is rendered makes it very hard to look right.
I found a good compromise is to use a proxy model to manipulate your styling. It is easier than creating a delegate for most formatting needs.
"They do all the rendering. You don’t have to use the roles to control how your item is rendered"
You may don't have to, but you should even not be able to. The model has definitely nothing to do with the style. Subclassing a delegate isn't really easier than subclassing a model (I'd say it's actually the same complexity).
Maybe changing a specific cell would be difficult, even so I dont actually see why. Just think about CSS styles, you can change style for a specific div. Anyway, it IS NOW difficult to it.
And I don't see either why a change in data would make it a problem (I'm no expert, but model would emit a signal, dataChanged, with the index and the new value which your render/formatter would capture).
Actually, my point is, delegate or not and whatever implementation adopted, there should be some kind of simple mechanism, involving few code, maybe no code at all actually, making you decide which format to adopt for each column (integer, float, money, percentage etc...). This is possible in many other model/view implementation (I'm thinking Ext, YahooUI, and I'm sure many others), so I don't think it is such a crazy request. All the more when I read some discussions in this forum.
Anyway, I came to these considerations facing a specific problem : I use a treeview with datas frequently changed and I would like to make the corresponding cell "flashing" in some way, let's say with a fading red backgroud for example.
I finally made it via the proxymodel, but isn't there a more "elegant" solution (my dream would be to use a QAnimation with one property and that would be all) ?
Thanks very much !
Use QML then. Whatever. The system is what it is. Is it ideal? No. Is it good? Yes. Is it a classic MVC implementation? No. If you really don't like it, I suggest you come up with a viable alternative. Don't count on Nokia doing it for you; there is little interest there in further developing this part of of Qt.
Just making an modest observation for further improvement, as advised by Nokia itself...
In fact, there wouldn't be so much to change. Right now there is already a beautiful mechanism, the stylesheet, that makes it possible to style some properties of a treeview, like the background color for example. So one possibility would be to extend these properties (with something like CSS selectors, allowing to select specific row and/or columns, and even items). For example I don't understand why it's not possible to set the text-align of a qtreeview via the stylesheet, while it is with some other widgets ? (or maybe it is, but I failed to find how).
Otherwise I finally got the right way to "flash" a specific item, indeed subclassing itemdelegate, so if anyone is interested, just ask....