[Qt-interest] changing style of a QListViewItem

Andre Somers andre at familiesomers.nl
Wed May 26 11:03:15 CEST 2010


On 26-5-2010 10:40, Mandeep Sandhu wrote:
>> How will setting a role change the appearance of the selected text?
>> Wouldn't  a custom delegate be needed anyway?
>>
>> IMHO, bold and underlined is just a different way of showing the
>> "selected" state, so that should be the job of a delegate. CMIIW.
>>
>>
>> If the OP wanted to display the selected state, you are right. You need a
>> delegate (or a different style). But double clicking isn't changing the
>> selected state, in my book. However, I may have misunderstood.
>>
>> You can change the font by using QAbstractItemModel::data and returning
>> something sensible for the Qt::FontRole. You can als modify colors
>>      
> Ah yes...the Qt::FontRole. Had forgotten about that!
>
> I guess this approach should be used if we always want to show the
> models data in the same manner, no matter what view is being used
> (provided the view doesn't override it with its delegate). If the OP
> wants that, then I guess this is way to do it.
>    
If not, you still need to save the state in the model somehow, even if 
it is in a custom role or some special flag. How else is your custom 
delegate going to know how to render the item?
If you want different views to have a different way of presenting the 
same information, indeed you should use degeates. Or you use a different 
proxy model that sets the appropriate flags or data items, if you can 
get away with that.

If the same model is used for more than one view, and the "double 
clicked state" state of those views should be independent (just like the 
selection can be), the situation gets even more complicated I fear. You 
will have to implement some kind of parallel model to keep track of that 
state, and either access it from a proxy model or from the delegate. 
Anyway, it is not clear at all that the OP needs such a complicated 
setup, so let's wait to hear back from him/her (not sure, not familiar 
with this name) before speculating more about such exotic solutions :-)

André


André




More information about the Qt-interest-old mailing list